/******************************************************************************
This file replicates the tables and figures in the paper:

			  Parent Training and Child Development at Low Cost?
			Evidence from a Randomized Field Experiment in Mexico

			         By Cárdenas, Evans and Holland

Input: 		completa.dta
Output:		Tables of statistics
			Log file
*******************************************************************************/

/**************************************
00. Housekeeping
***************************************/

clear 
set more off
cd "<INSERT NEW FILE PATH HERE>"
* example:
* cd "/Users/amina/Dropbox/Amina CGD/Amina-Dave/Mexico Early Education/Mexico ECD Replication packet"

capture: ssc install tabcount
capture: ssc install swindex
capture: ssc install icw_index
capture: ssc install estout
capture: ssc install esttab
capture: ssc instell outreg2

* Generate log file
	capture log close _all
	log using "Mexico ECD_logfile", replace

/**************************************
 ANALYSIS
***************************************/
	
* Load input file	
use completa.dta

*---------------------------------------*
*                                       *
*Generating dummy variables for analysis*
*                                       *
*---------------------------------------*
sort ID_HOG_RECOD ID_HOG_IND_RECOD wave
gen trt = (tipo_grupo==1) //treatment
encode ID_LOC, gen(community) //community 
encode ID_HOG_RECOD, gen(hogar) //home
gen wave2=(wave==2) //year 1
gen wave3=(wave==3) //year 2
gen trt_2 = trt*wave2 //treatment at year 1
gen trt_3 = trt*wave3 //treatment at year 2

gen girl = (sexo==2) //girl
gen age = cuest // age

***** Table 1. Table 1: Descriptive Statistics of the Study Population  *****

tab girl
tab age

tab P9_3_HO // caregiver's gender

replace P9_4_1_HO = . if P9_4_1_HO < 10 | P9_4_1_HO == 888 //clean data
su P9_4_1_HO // caregiver's age

tab parentesco // relationship to child

* Spanish only
gen spanish_only = 0
replace spanish_only = 1 if P8_0_1_CU == 1 | P8_0_2_CU == 1 | P8_0_3_CU == 1 // speaks spanish
replace spanish_only = 0 if P8_0_1_CU == 2 | P8_0_2_CU == 2 | P8_0_3_CU == 2 // less if other language
replace spanish_only  = 0 if P8_0_1_CU == 3 | P8_0_2_CU == 3 | P8_0_3_CU == 3
tab spanish_only

* Indigenous language only
gen ind_only = 0
replace ind_only = 1 if P8_0_1_CU == 2 | P8_0_2_CU == 2 | P8_0_3_CU == 2 // speaks ind
replace  ind_only = 0 if P8_0_1_CU == 1 | P8_0_2_CU == 1 | P8_0_3_CU == 1 // less if other language
replace ind_only  = 0 if P8_0_1_CU == 3 | P8_0_2_CU == 3 | P8_0_3_CU == 3
tab ind_only

* Level of education
tab P9_9_1_HO

* Materials composition of household
	* walls
	tab P10_HO
	
	* roof made of metal or asbestos = Lumina metalica + lumina de asbesto 
	* roof made of concrete ceiling = Losa de concreto...
	tab P11_HO
	
	* solid or cement floor = cemento o firme
	tab P12_HO
	
	* number of rooms
	tab P13_HO

	* number of bedrooms
	tab P14_HO
	
	* electricity: >= 3
	tab P15_HO

	* water source: first two rows (entubada dentor + entubabda fuera)
	tab P16_HO

	* access to water: seven times a week
	tab P17_HO
	
	* access to bathroom and toilet
	tab P18_HO

	* gas stove
	tab P22_1_HO
	
	* wood stove
	tab P22_2_HO
	
	* water tank
	tab P22_3_HO
	
	* water heater
	tab P22_4_HO
	
	* cistern
	tab P22_5_HO
	
	* shower
	tab P22_6_HO
	
	* electricity meter
	tab P22_7_HO

	* car
	tab P23_1_HO
	
	* internet
	tab P23_2_HO
	
	* computer
	tab P23_3_HO
	
	* landline phone
	tab P23_4_HO
	
	* cellphone
	tab P23_5_HO
	
	* washing machine
	tab P23_6_HO
	
	* refrigerator
	tab P23_7_HO
	
	* television
	tab P23_8_HO
	
	* radio
	tab P23_9_HO

*---------------------------------------*
*                                       *
*            Take-up statistics         *
*                                       *
*---------------------------------------*
*----Generating variables of total sessions attended----*
gen sesionestotal1 = P5_CU if wave==1
gen sesionestotal2 = P5_CU if wave==2
gen sesionestotal3 = P5_CU if wave==3

*----Taking out outliers----*
foreach x in sesionestotal1 sesionestotal2 sesionestotal3 {
	replace `x'=. if `x' >80
	replace `x'=40 if `x'>40 & `x'<81
/* WE USE 40 BECAUSE THAT'S THE MAX OFFICIAL OBSERVATIONS. */
	}

*----Generating variables of total sessions attened in each wave----*
bys hogar: egen sesionestotal1a = mean(sesionestotal1)
bys hogar: egen sesionestotal2a = mean(sesionestotal2)
bys hogar: egen sesionestotal3a = mean(sesionestotal3)

replace sesionestotal1a=0 if sesionestotal1a==.
replace sesionestotal2a=0 if sesionestotal2a==.
replace sesionestotal3a=0 if sesionestotal3a==.
gen sesionestotal = sesionestotal1a + sesionestotal2a + sesionestotal3a

*----Setting IV indicators for sessions attened in each wave----*
gen attended_any = (sesionestotal > 0)
gen attended_any2 = attended_any*wave2
gen attended_any3 = attended_any*wave3


**** Label variables ****
label var attended_any "Attended any session"
label var attended_any2 "Attended any session in Year 1"
label var attended_any3 "Attended any session in Year 2"

label var trt 	"Assigned to Treatment"
label var trt_2 "Assigned to Treatment in Year 1"
label var trt_3	"Assigned to Treatment in Year 2"

***** Table 4: First-stage estimates *****
reg attended_any trt
outreg2 using "Tables/Table 4. First-stage estimates.xls", replace word label dec(2)
reg attended_any2 trt_2 if wave2 == 1
outreg2 using "Tables/Table 4. First-stage estimates.xls", append word label dec(2)
reg attended_any3 trt_3 if wave3 == 1
outreg2 using "Tables/Table 4. First-stage estimates.xls", append word label dec(2)

sum sesionestotal if sesionestotal > 0, d

gen attended_med = (sesionestotal >= r(p50))

*----Creating a flag for each caregiver----*
bys hogar wave CuidID: gen n=_n

*-----------------------------*
*---- Summarizing take-up----***
*-----------------------------*

***** Table A2: Intermediate results: take-up *****
putexcel set "Tables/Table A2. Intermediate results: take-up.xls", replace
putexcel A2 = "Baseline"
putexcel A3 = "Year 1"
putexcel A4 = "Year 2"
putexcel B1 = "Mean"
putexcel C1 = "Median"
putexcel D1 = "25th percentile"
putexcel E1 = "75th percentile"

sum sesionestotal1a if n==1 & tipo_grupo==1 & wave==1 & CuidID==1,d
putexcel B2 = `r(mean)'
putexcel C2 = `r(p50)'
putexcel D2 = `r(p25)'
putexcel E2 = `r(p75)'

sum sesionestotal2a if n==1 & tipo_grupo==1 & wave==1 & CuidID==1,d
putexcel B3 = `r(mean)'
putexcel C3 = `r(p50)'
putexcel D3 = `r(p25)'
putexcel E3 = `r(p75)'

sum sesionestotal3a if n==1 & tipo_grupo==1 & wave==1 & CuidID==1,d
putexcel B4 = `r(mean)'
putexcel C4 = `r(p50)'
putexcel D4 = `r(p25)'
putexcel E4 = `r(p75)'


***** Figure 1 ******
tabcount sesionestotal1a  if n==1 & tipo_grupo==1 & wave==1 & CuidID==1, v1(0/40)
tabcount sesionestotal2a  if n==1 & tipo_grupo==1 & wave==1 & CuidID==1, v1(0/40)
tabcount sesionestotal3a  if n==1 & tipo_grupo==1 & wave==1 & CuidID==1, v1(0/40)

*--------------------------------------------*
*                                            *
*Attrition Statistics and Regression Analysis*
*                                            *
*--------------------------------------------*

*--------------------------------------------*
*--------------CHILD ATTRITION---------------*
*--------------------------------------------*
*----Generating dummies for attrition analysis-----*
egen asq_present_tmp = rowmiss(pcom pmotg pmotf presp psoci)
gen asq_present = (asq_present_tmp==0) if ChildID==1 //attendance dummy

gen asq_present_b_tmp = asq_present if wave==1 & ChildID==1 //attendance at baseline
bys ID_HOG_IND_RECOD: egen asq_present_b = mean(asq_present_b_tmp) if ChildID==1 //
//dummy for attendance at baseline

gen asq_present_2_tmp = asq_present if wave==2 & ChildID==1 //attendance at year 1
bys ID_HOG_IND_RECOD: egen asq_present_2 = mean(asq_present_2_tmp) if ChildID==1 //
//dummy for attendance at year 1

gen asq_present_3_tmp = asq_present if wave==3 & ChildID==1 //attendance at year 2
bys ID_HOG_IND_RECOD: egen asq_present_3 = mean(asq_present_3_tmp) if ChildID==1 //
//dummy for attendance at year 2

*-------------------------------------------*
*---------CHILD Attrition statistics--------*
*-------------------------------------------*

**** Label variables ****
label var asq_present_b "Present at Baseline"
label var asq_present_2 "Present at Year 1"
label var asq_present_3 "Present at Year 2"

***** Table 3: Attrition descriptive statistics (Children) *****
estpost su asq_present_b asq_present_2 asq_present_3 if wave==1 & ChildID==1 & trt == 1
esttab using "Tables/Table 3. Attrition.xls", label cells(count) replace title("Children - treatment")

estpost su asq_present_b asq_present_2 asq_present_3 if wave==1 & ChildID==1 & trt == 0
esttab using "Tables/Table 3. Attrition.xls", label cells(count) append title("Children - control")

*---------------------------------------------*
*--------------PARENT ATTRITION---------------*
*---------------------------------------------*
*----Generating dummies for attrition analysis-----*
egen cuid_present_tmp = rowmiss(P14_CU - P54_CU)
gen cuid_present = (cuid_present_tmp!=79) if CuidID==1 //attendance dummy
//we use 79 because it's the number of all parenting questions//

gen cuid_present_b_tmp = cuid_present if wave==1 & CuidID==1 //attendance at baseline
bys ID_HOG_IND_RECOD_CU: egen cuid_present_b = mean(cuid_present_b_tmp) if CuidID==1 
//dummy for attendance at baseline

gen cuid_present_2_tmp = cuid_present if wave==2 & CuidID==1 //attendance at year 1 
bys ID_HOG_IND_RECOD_CU: egen cuid_present_2 = mean(cuid_present_2_tmp) if CuidID==1
//dummy for attendance at year 1

gen cuid_present_3_tmp = cuid_present if wave==3 & CuidID==1 //attendance at year 2
bys ID_HOG_IND_RECOD_CU: egen cuid_present_3 = mean(cuid_present_3_tmp) if CuidID==1
//dummy for attendance at year 2 

*--------------------------------------------*
*--------PARENT Attrition statistics---------*
*--------------------------------------------*

**** Label variables ****
label var cuid_present_b "Present at Baseline"
label var cuid_present_2 "Present at Year 1"
label var cuid_present_3 "Present at Year 2"

***** Table 3: Attrition descriptive statistics (Parent) *****
estpost su cuid_present_b cuid_present_2 cuid_present_3 if wave==1 & CuidID==1& trt == 1
esttab using "Tables/Table 3. Attrition.xls", label cells(count) append title("Caregiver - treatment")

estpost su cuid_present_b cuid_present_2 cuid_present_3 if wave==1 & CuidID==1& trt == 0
esttab using "Tables/Table 3. Attrition.xls", label cells(count) append title("Caregiver - control")

*------------------------------------------------*
*                                                *
*        Child Development Characteristics       * 
*                                                *
*------------------------------------------------*

*----standardizing ASQ scores for analysis----*
foreach var of varlist pcom pmotg pmotf presp psoci{
sum `var' if ChildID==1  //sum mean and standard error
gen `var'_std=(`var'-r(mean))/r(sd)  //standardizing the scores 
sum `var'_std if ChildID==1  //testing the results 
}

***** Generating alterative indices *******

* ASQ Total
gen asq_total = pcom_std + pmotg_std + pmotf_std + presp_std + psoci_std

*ASQ Total Standardized
sum asq_total if ChildID==1  //sum mean and standard error
gen asq_total_std=(asq_total-r(mean))/r(sd)  //standardizing the scores 
sum asq_total_std if ChildID==1  //testing the results 

*PCA Standardized
pca pcom_std pmotg_std pmotf_std presp_std psoci_std if CuidID==1 & cuid_present_b==1
predict asq_pca, score
sum asq_pca if ChildID==1  //sum mean and standard error
gen asq_pca_std=(asq_pca-r(mean))/r(sd)  //standardizing the scores 
sum asq_pca_std if ChildID==1  //testing the results 

*ICW Index Standardized
icw_index pcom_std pmotg_std pmotf_std presp_std psoci_std, gen(asq_icw)
sum asq_icw if ChildID==1  //sum mean and standard error
gen asq_icw_std=(asq_icw-r(mean))/r(sd)  //standardizing the scores 
sum asq_icw_std if ChildID==1  //testing the results

*SW Index
swindex pcom pmotg pmotf presp psoci, gen(asq_sw)

sum asq_total_std asq_total asq_pca_std asq_icw_std asq_sw

*---------------------------*
*----BALANCE at baseline----*
*---------------------------*

**** Label variables ****
label var pcom_std "ASQ: Communication (standardized)"
label var pmotg_std "ASQ: Gross motor (standardized)"
label var pmotf_std "ASQ: Fine motor (standardized)"
label var presp_std "ASQ: Problem solving (standardized)"
label var psoci_std "ASQ: Social (standardized)"
label var asq_total_std "ASQ: Total (standardized)"

***** Table 2: Balance across ASQ & Observed Characteristics (ASQ) *****
foreach var of varlist pcom_std pmotg_std pmotf_std presp_std psoci_std{
	reg `var' trt if wave==1 & ChildID==1 & asq_present_b ==1, vce(cluster community)
	local pval = r(table)[4,1]
	lincom _cons+trt
	local Treatment=r(estimate)
	outreg2 using "Tables/Table 2. Baseline Balance.xls", append word label dec(2) addstat("Treatment",`Treatment', "P-val", `pval')
}

*------------------------------------*
*----Child development regression----*
*------------------------------------*
***** Table 8: Impact on Child Development (full sample of children, ages 0-72 months) *****
xtreg asq_total_std trt_2 trt_3 wave2 wave3 if ChildID==1 & asq_present_b==1 , fe i(community)vce(cluster community)
    outreg2 using "Tables/Table 8. Child Development Outcomes.xls", replace word label dec(2)
	
foreach var in pcom_std pmotg_std pmotf_std presp_std psoci_std {
	d `var'
	xtreg `var' trt_2 trt_3 wave2 wave3 if ChildID==1 & asq_present_b==1 , fe i(community)vce(cluster community)
    outreg2 using "Tables/Table 8. Child Development Outcomes.xls", append word label dec(2)
	}

* TOT analysis
xtivreg asq_total_std (attended_any2 attended_any3 = trt_2 trt_3) wave2 wave3 if ChildID==1 & asq_present_b==1 , fe i(community)vce(cluster community)
    outreg2 using "Tables/Table A8. Child Development_TOT.xls", replace word label dec(2)
foreach var in pcom_std pmotg_std pmotf_std presp_std psoci_std{
	d `var'
	xtivreg `var' (attended_any2 attended_any3 = trt_2 trt_3) wave2 wave3 if ChildID==1 & asq_present_b==1 , fe i(community)vce(cluster community)
    outreg2 using  "Tables/Table A8. Child Development_TOT.xls", append word label dec(2)
	}

**** indices comparison *****

xtreg asq_total_std trt_2 trt_3 wave2 wave3 if ChildID==1 & asq_present_b==1 , fe i(community)vce(cluster community)
    outreg2 using "Tables/Table A22. Child Development_alternative indices.xls", replace word label dec(2)
xtreg asq_total trt_2 trt_3 wave2 wave3 if ChildID==1 & asq_present_b==1 , fe i(community)vce(cluster community)
    outreg2 using "Tables/Table A22. Child Development_alternative indices.xls", append word label dec(2)
xtreg asq_pca_std trt_2 trt_3 wave2 wave3 if ChildID==1 & asq_present_b==1 , fe i(community)vce(cluster community)
    outreg2 using "Tables/Table A22. Child Development_alternative indices.xls", append word label dec(2)	
xtreg asq_icw_std trt_2 trt_3 wave2 wave3 if ChildID==1 & asq_present_b==1 , fe i(community)vce(cluster community)
    outreg2 using "Tables/Table A22. Child Development_alternative indices.xls", append word label dec(2)
xtreg asq_sw trt_2 trt_3 wave2 wave3 if ChildID==1 & asq_present_b==1 , fe i(community)vce(cluster community)
    outreg2 using "Tables/Table A22. Child Development_alternative indices.xls", append word label dec(2)

***** Table A9. Impact on Child Development (full sample of children, aged 0-72 months) by intensity of participation *****
	
* Analysis indicator for attending at least one
	xtreg asq_total_std attended_any wave2 wave3  if ChildID==1 & asq_present_b==1 , fe i(community)vce(cluster community)
    outreg2 using   "Tables/Table A9. Child Development by intensity of participation.xls", replace word label dec(2)

* Analysis indicator for attending at least median 
	xtreg asq_total_std attended_med wave2 wave3  if ChildID==1 & asq_present_b==1 , fe i(community)vce(cluster community)
    outreg2 using  "Tables/Table A9. Child Development by intensity of participation.xls", append word label dec(2)

* Analysis indicator for attending at least median 
	xtreg asq_total_std sesionestotal wave2 wave3  if ChildID==1 & asq_present_b==1 , fe i(community)vce(cluster community)
    outreg2 using  "Tables/Table A9. Child Development by intensity of participation.xls", append word label dec(2)
	
*----------------------------------------------------*
*------Heterogeneous treatment effects analysis------*
*----------------------------------------------------*

*---------------------------*
*----GENDER OF THE CHILD----*
*---------------------------*
*----Generating gender dummies----*
gen girl_trt = girl*trt  //Girl treatment 
gen trt_girl_2 = girl*trt_2  //Girl treatment at year 1
gen trt_girl_3 = girl*trt_3  //Girl treatment at year 2

*------------------*
*----Regression----*
*------------------*

***** Table A10: Heterogeneous Effects on Child Development Based on Gender of Child ******
foreach x in asq_total_std pcom_std pmotg_std pmotf_std presp_std psoci_std {
	xtreg `x' trt_girl_2 trt_girl_3 girl wave2 wave3 trt_2 trt_3 if ChildID==1 & asq_present_b ==1 ,fe i(community) vce(cluster community)     
	local t2 = _b[trt_girl_2]/_se[trt_girl_2]   //calculating t-score of gender difference effect at year1
	local p2 = 2*ttail(e(df_r),abs(`t2'))     //calculating p-value of gender difference effect at year 1
	local t3 = _b[trt_girl_3]/_se[trt_girl_3]  //calculating t-score of gender difference effect  at year 2
	local p3 = 2*ttail(e(df_r),abs(`t3'))   //calculating p-value of gender difference effect at year 2
	lincom trt_2 + trt_girl_2    
	local coef2 = r(estimate)    //coefficient of girl at year 1 
	local se2 = r(se)           //standard error of girl at year 1 
	lincom trt_3 + trt_girl_3
	local coef3 = r(estimate)	//coefficient of girl at year 2
	local se3 = r(se)          //standard error of girl at year 2
	gen sample_`x'=e(sample) 
	count if ChildID==1 & sample_`x'==1 & wave==1
	outreg2 using "Tables/Table A10. ASQ by Gender.xls", append word label dec(2)
    }

*----------------------------------------*
*----AGE OF THE CHILD (36 MONTHS CUT)----*
*----------------------------------------*

*----Generating age dummies----* 
gen age_36below = (cuest<36) if wave==1 & ChildID==1 & asq_present_b ==1 
bys ID_HOG_IND_RECOD: egen age_d = mean(age_36below)
gen age_2 = age_d*trt_2
gen age_3 = age_d*trt_3

*------------------*
*----Regression----*
*------------------*
***** Table A11 Heterogeneous Effects of Child Development Based on Baseline Age of Child (divided at 36 months)
foreach x in asq_total_std pcom_std pmotg_std pmotf_std presp_std psoci_std {
	xtreg `x' age_2 age_3 age_d wave2 wave3 trt_2 trt_3 if ChildID==1 & asq_present_b ==1 ,fe i(community) vce(cluster community)     
	local t2 = _b[age_2]/_se[age_2]   //calculating t-score of age difference effect at year 1 
	local p2 = 2*ttail(e(df_r),abs(`t2'))  //calculating p-value of age difference effect at year 1
	local t3 = _b[age_3]/_se[age_3]  //calculating t-score of age difference effect at year 2
	local p3 = 2*ttail(e(df_r),abs(`t3'))  //calculating t-score of age difference effect at year 2
	lincom trt_2 + age_2
	local coef2 = r(estimate)  //coefficient of younger kids at year 1
	local se2 = r(se)  //standard error of younger kids at year 1
	lincom trt_3 + age_3    
	local coef3 = r(estimate)	//coefficient of younder kids at year 2
	local se3 = r(se)   //standard erros of younder kids at year 2 
	gen age1_`x'=e(sample)
	count if ChildID==1 & age1_`x'==1 & wave==1
	outreg2 using "Tables/Table A11. ASQ by age (divided at 36 months).xls", append word label dec(2)
    }

	
*----------------------------------------*
*----AGE OF THE CHILD (22 MONTHS CUT)----*
*----------------------------------------*
*----Generating age dummies----*
gen age2 = (cuest<22) if wave==1 & ChildID==1 & asq_present_b ==1 
bys ID_HOG_IND_RECOD: egen age_d_2 = mean(age2)
gen age_2_2 = age_d_2*trt_2
gen age_3_2 = age_d_2*trt_3

*------------------*
*----Regression----*
*------------------*
***** Table A12: Hetergenous Effects of Child Development Based on Baseline Age of Child (divided at 22 months)
foreach x in asq_total_std pcom_std pmotg_std pmotf_std presp_std psoci_std {
	xtreg `x' age_2_2 age_3_2 age_d_2 wave2 wave3 trt_2 trt_3 if ChildID==1 & asq_present_b ==1 ,fe i(community) vce(cluster community)     
	local t2 = _b[age_2]/_se[age_2]    //calculating t-score of age difference effect at year 1 
	local p2 = 2*ttail(e(df_r),abs(`t2'))   //calculating p-value of age difference effect at year 1
	local t3 = _b[age_3]/_se[age_3]    //calculating t-score of age difference effect at year 2
	local p3 = 2*ttail(e(df_r),abs(`t3'))   //calculating t-score of age difference effect at year 2
	lincom trt_2 + age_2_2
	local coef2 = r(estimate)   //coefficient of younger kids at year 1
	local se2 = r(se)      //standard error of younger kids at year 1
	lincom trt_3 + age_3_2
	local coef3 = r(estimate)   //coefficient of younder kids at year 2
	local se3 = r(se)      //standard erros of younder kids at year 2 
	gen age2_`x'=e(sample)
	count if ChildID==1 & age2_`x'==1 & wave==1
	outreg2 using "Tables/Table A12. ASQ by age (divided at 22 months).xls", append word label dec(2)
    }

*--------------------------------------------*
*                                            *
*   Observed Parenting Practices Analysis    * 
*                                            *
*--------------------------------------------*
*----Generating dummy variables for observed parenting practices----*
foreach x in P64_CU P65_CU P66_CU P67_CU P68_CU P69_CU P70_CU P71_CU P72_CU P73_CU P74_CU P75_CU P76_CU P77_CU P78_CU P79_CU P80_CU P81_CU P82_CU P83_CU P84_CU {
	gen dummy_`x'=2-`x'
	replace dummy_`x'=. if dummy_`x'<0
	}
*----Labeling variables for age 0-35 months----*
la var dummy_P64_CU "OBS: Madre y niño juntos" 
la var dummy_P65_CU "OBS: Madre habló con niño" 
la var dummy_P66_CU "OBS: Madre resPondió" 
la var dummy_P67_CU "OBS: Madre acarició o besó" 
la var dummy_P68_CU "OBS: Madre dio cachetada o nalgada" 
la var dummy_P69_CU "OBS: Madre interfirió con acciones de niño" 
la var dummy_P70_CU "OBS: Madre dio juguetes o actividades" 
la var dummy_P71_CU "OBS: Madre mantuvo niño a la vista" 
la var dummy_P72_CU "OBS: Area de juego es segura" 


*----Labeling variables for age 36-72 months----*
la var dummy_P73_CU "OBS: Madre y niño juntos" 
la var dummy_P74_CU "OBS: Madre conversó 2x" 
la var dummy_P75_CU "OBS: Madre resPondió" 
la var dummy_P76_CU "OBS: Madre acarició o besó" 
la var dummy_P77_CU "OBS: Madre Presento a niño Por nombre"
la var dummy_P78_CU "OBS: Madre restringió o saCUdió"
la var dummy_P79_CU "OBS: Madre dio cachetada o nalgada" 
la var dummy_P80_CU "OBS: Voz de madre reflejó sentimiento Positivo acerca niño" 
la var dummy_P81_CU "OBS: Area de juego es segura" 
la var dummy_P82_CU "OBS: Interio de la casa es osCUro" 
la var dummy_P83_CU "OBS: Cuartos estaban limPios" 
la var dummy_P84_CU "OBS: Cuartos no estaban abarrotados de cosas"


*----Generating combined dummy variables for observations shared by both groups----*
egen D6473=rowmean(dummy_P64_CU  dummy_P73_CU)
egen D6574=rowmean(dummy_P65_CU  dummy_P74_CU)
egen D6675=rowmean(dummy_P66_CU  dummy_P75_CU)
egen D6776=rowmean(dummy_P67_CU  dummy_P76_CU)
egen D6879=rowmean(dummy_P68_CU  dummy_P79_CU)
egen D6978=rowmean(dummy_P69_CU  dummy_P78_CU)
egen D7281=rowmean(dummy_P72_CU  dummy_P81_CU)

*----Labeling combined dummy variables----*
la var D6473 "[Cuid 0-6]OBS: Madre y niño juntos"
la var D6574 "[Cuid 0-6]OBS: Madre habló con niño" 
la var D6675 "[Cuid 0-6]OBS: Madre resPondió" 
la var D6776 "[Cuid 0-6]OBS: Madre acarició o besó" 
la var D6879 "[Cuid 0-6]OBS: Madre dio cachetada o nalgada" 
la var D6978 "[Cuid 0-6]OBS: Madre interfirió con acciones de niño"
la var D7281 "[Cuid 0-6]OBS: Area de juego es segura"

*----Generating indices-----*

* 0-35
* Flip sign for incidence of violence and interference
replace dummy_P68_CU = 1-dummy_P68_CU
replace dummy_P69_CU = 1-dummy_P69_CU

* Standardizing dummy variables for observed parenting practices
foreach var of varlist dummy_P64_CU-dummy_P72_CU {
sum `var' if ChildID==1  //sum mean and standard error
gen `var'_std=(`var'-r(mean))/r(sd)  //standardizing the scores 
sum `var'_std if ChildID==1  //testing the results 
}

* PCA
pca dummy_P64_CU_std-dummy_P72_CU_std if CuidID==1 & cuid_present_b==1
predict opi_pca, score
sum opi_pca if ChildID==1  //sum mean and standard error
gen opi_pca_std=(opi_pca-r(mean))/r(sd)  //standardizing the scores 
sum opi_pca_std if ChildID==1  //testing the results 

* ICW
icw_index dummy_P64_CU_std-dummy_P72_CU_std, gen(opi_icw)
sum opi_icw if ChildID==1  //sum mean and standard error
gen opi_icw_std=(opi_icw-r(mean))/r(sd)  //standardizing the scores 
sum opi_icw_std if ChildID==1  //testing the results 

* SW
swindex dummy_P64_CU_std-dummy_P72_CU_std if CuidID==1 & cuid_present_b==1, gen(opi_sw)

sum opi_pca_std opi_icw_std opi_sw

* 36 to 72


* flip sign for interference, incidence of violence, dark house, and house not packed
replace dummy_P78_CU = 1-dummy_P78_CU
replace dummy_P79_CU = 1-dummy_P79_CU
replace dummy_P82_CU = 1-dummy_P82_CU

foreach var of varlist dummy_P73_CU-dummy_P84_CU {
sum `var' if ChildID==1  //sum mean and standard error
gen `var'_std = (`var'-r(mean))/r(sd)  //standardizing the scores 
sum `var'_std if ChildID==1  //testing the results 
}
*----Generating parenting index (36-72 months)----*
pca dummy_P73_CU_std - dummy_P84_CU_std if CuidID==1 & cuid_present_b==1
predict opi2_pca, score
sum opi2_pca if ChildID==1  //sum mean and standard error
gen opi2_pca_std = (opi2_pca-r(mean))/r(sd)  //standardizing the scores 
sum opi2_pca_std if ChildID==1  //testing the results 

*----BALANCE----*
*---------------*

**** Label variables ****
label var dummy_P64_CU_std "0-35 std: parent and children together"
label var dummy_P65_CU_std "0-35 std: spoke to children"
label var dummy_P66_CU_std "0-35 std: parent responded"
label var dummy_P67_CU_std "0-35 std: parent hugged or kissed"
label var dummy_P68_CU_std "0-35 std: parent did not use corporal punishment"
label var dummy_P69_CU_std "0-35 std: parent did not interfere"
label var dummy_P70_CU_std "0-35 std: parent gave games"
label var dummy_P71_CU_std "0-35 std: kept children in sight"
label var dummy_P72_CU_std "0-35 std: safe play area"

label var dummy_P73_CU_std "36-72 std: parent and children together"
label var dummy_P74_CU_std "36-72 std: spoke to children"
label var dummy_P75_CU_std "36-72 std: parent responded"
label var dummy_P76_CU_std "36-72 std: parent hugged and kissed"
label var dummy_P77_CU_std "36-72 std: parent introduced children"
label var dummy_P78_CU_std "36-72 std: parent did not restrain or shake"
label var dummy_P79_CU_std "36-72 std: parent did not slap or spank"
label var dummy_P80_CU_std "36-72 std: parent reflected positive attitude"
label var dummy_P81_CU_std "36-72 std: safe play area"
label var dummy_P82_CU_std "36-72 std: bright house interior"
label var dummy_P83_CU_std "36-72 std: clean rooms"
label var dummy_P84_CU_std "36-72 std: house not packed"


***** Table 2: Balance across ASQ & Observed Characteristics (Caregiver) *****
*----0-35 Months----*
foreach var of varlist dummy_P64_CU_std-dummy_P72_CU_std{
	reg `var' trt if wave==1 & ChildID==1 & asq_present_b ==1, vce(cluster community)
	local pval = r(table)[4,1]
	lincom _cons+trt
	local Treatment=r(estimate)
	outreg2 using "Tables/Table 2. Baseline Balance.xls", append word label dec(2) addstat("Treatment",`Treatment', "P-val", `pval')
	}
	
*----36-72 Months----*
foreach var of varlist dummy_P73_CU_std - dummy_P84_CU_std {
	reg `var' trt if wave==1 & ChildID==1 & asq_present_b ==1, vce(cluster community)
	local pval = r(table)[4,1]
	lincom _cons+trt
	local Treatment=r(estimate)
	outreg2 using "Tables/Table 2. Baseline Balance.xls", append word label dec(2) addstat("Treatment",`Treatment', "P-val", `pval')
	}
	

*----------------------------------------------------------------*
*----OBSERVED PARENTING PRACTICES REGRESSIONS AGE 0-35 MONTHS----*
*----------------------------------------------------------------*
*---------------------------------*
*----Regressions (0-35 months)----*
*---------------------------------*

*----Generating index regression sample (0-35 months)----*
xtreg dummy_P64_CU_std trt_2 trt_3 wave2 wave3 if CuidID==1 & cuid_present_b==1, fe i(community) 
gen sample_tmp=e(sample)

***** Table 5: Impact on Observed Parenting Practices–- 9 practices + an index–- age (0-35 months) *****
xtreg opi_pca_std trt_2 trt_3 wave2 wave3 if sample_tmp==1 & CuidID==1 & cuid_present_b==1, fe i(community) vce(cluster ID_LOC)
outreg2 using  "Tables/Table 5. Observed Parenting 0-35 (9 practices).xls", replace word label dec(2)

foreach var of varlist dummy_P64_CU_std-dummy_P72_CU_std {
	d `var' 
	xtreg `var' trt_2 trt_3 wave2 wave3 if sample_tmp==1 & CuidID==1 & cuid_present_b==1, fe i(community) vce(cluster ID_LOC)	
	gen sample_`var'=e(sample)
	count if CuidID==1 & sample_`var'==1 & wave==1  //counting baseline sample size 
	outreg2 using  "Tables/Table 5. Observed Parenting 0-35 (9 practices).xls", append word label dec(2)
	}
	
***** TOT Analysis *****
xtivreg opi_pca_std (attended_any2 attended_any3 = trt_2 trt_3) wave2 wave3 if sample_tmp==1 & CuidID==1 & cuid_present_b==1, fe i(community) vce(cluster ID_LOC)
outreg2 using  "Tables/Table A3. Observed Parenting 0-35 (9 practices)_TOT.xls", replace word label dec(2)

foreach var of varlist dummy_P64_CU dummy_P65_CU dummy_P66_CU dummy_P67_CU dummy_P68_CU dummy_P69_CU dummy_P70_CU dummy_P71_CU dummy_P72_CU {
	d `var' 
	xtivreg `var' (attended_any2 attended_any3 = trt_2 trt_3) wave2 wave3 if CuidID==1 & cuid_present_b==1, fe i(community) vce(cluster ID_LOC)	
	gen sampleTOT_`var'=e(sample)
	count if CuidID==1 & sample_`var'==1 & wave==1  //counting baseline sample size 
	outreg2 using  "Tables/Table A3. Observed Parenting 0-35 (9 practices)_TOT.xls", append word label dec(2)
	
	}


*----Generating index regression sample (0-35 months)----*
xtreg dummy_P64_CU trt_2 trt_3 wave2 wave3 if CuidID==1 & cuid_present_b==1, fe i(community) 
replace sample_tmp=e(sample)

*----Comparing across different indices (0-35 months)----*
xtreg opi_pca_std trt_2 trt_3 wave2 wave3 if sample_tmp==1 & CuidID==1 & cuid_present_b==1, fe i(community) vce(cluster ID_LOC)
outreg2 using  "Tables/Table A19. Observed Parenting 0-35 (9 practices)_Alternative indices.xls", replace word label dec(2)
xtreg opi_icw_std trt_2 trt_3 wave2 wave3 if sample_tmp==1 & CuidID==1 & cuid_present_b==1, fe i(community) vce(cluster ID_LOC)
outreg2 using  "Tables/Table A19. Observed Parenting 0-35 (9 practices)_Alternative indices.xls", append word label dec(2)
xtreg opi_sw trt_2 trt_3 wave2 wave3 if sample_tmp==1 & CuidID==1 & cuid_present_b==1, fe i(community) vce(cluster ID_LOC)
outreg2 using  "Tables/Table A19. Observed Parenting 0-35 (9 practices)_Alternative indices.xls", append word label dec(2)

*----------------------------------------------------------------*
*----OBSERVED PARENTING PRACTICES REGRESSIONS AGE 36-72 MONTHS----*
*----------------------------------------------------------------*

	
***** Table A4: Impact on Observed Parenting Practices –- ages 36-72 months *****

*----Generating parenting index (36-72 months)----*

xtreg dummy_P73_CU_std trt_2 trt_3 wave2 wave3 if CuidID==1 & cuid_present_b==1, fe i(community) 
replace sample_tmp=e(sample)

xtreg opi2_pca_std trt_2 trt_3 wave2 wave3 if sample_tmp==1 & CuidID==1 & cuid_present_b==1, fe i(community) vce(cluster ID_LOC)	
outreg2 using "Tables/Table A4. Observed Parenting Practices (36-72).xls", replace word label dec(2)

foreach var of varlist dummy_P73_CU_std - dummy_P84_CU_std {
	d `var'
	xtreg `var' trt_2 trt_3 wave2 wave3 if CuidID==1 & cuid_present_b==1, fe i(community) vce(cluster ID_LOC)
	gen sample_`var'=e(sample)
	count if CuidID==1 & sample_`var'==1& wave==1 //counting baseline sample size 
	outreg2 using "Tables/Table A4. Observed Parenting Practices (36-72).xls", append word label dec(2)
	}


*----------------------------------------------------------------*
*----OBSERVED PARENTING PRACTICES REGRESSIONS AGE 0-72 MONTHS----*
*----------------------------------------------------------------*
*----------------------------------*
*----Regressions (0-72 months)----*
*----------------------------------*

* flip sign for incidence of violence and interference
replace D6879 = 1-D6879
replace D6978 = 1-D6978

*---- Standardizing dummy variables for observed parenting practices----*
foreach var of varlist D6473 D6574 D6675 D6776 D6879 D6978 D7281 {
sum `var' if ChildID==1  //sum mean and standard error
gen `var'_std=(`var'-r(mean))/r(sd)  //standardizing the scores 
sum `var'_std if ChildID==1  //testing the results 
}

* PCA
pca D6473_std D6574_std D6675_std D6776_std D6879_std D6978_std D7281_std if CuidID==1 & cuid_present_b==1
predict obi2_pca, score
sum obi2_pca if ChildID==1  //sum mean and standard error
gen obi2_pca_std=(obi2_pca-r(mean))/r(sd)  //standardizing the scores 
sum obi2_pca_std if ChildID==1  //testing the results 

* ICW
icw_index D6473_std D6574_std D6675_std D6776_std D6879_std D6978_std D7281_std, gen(obi2_icw)
sum obi2_icw if ChildID==1  //sum mean and standard error
gen obi2_icw_std=(obi2_icw-r(mean))/r(sd)  //standardizing the scores 
sum obi2_icw_std if ChildID==1  //testing the results

* SW
swindex D6473_std D6574_std D6675_std D6776_std D6879_std D6978_std D7281_std if CuidID==1 & cuid_present_b==1, gen(obi2_sw)

sum obi2_pca_std obi2_icw_std obi2_sw

***** Table 6: Impact on Observed Parenting Practices –- 7 practices + an index –- ages 0-72 months *****

*----Generating index regression sample (0-72 months)----*
xtreg D6473 trt_2 trt_3 wave2 wave3 if CuidID==1 & cuid_present_b==1, fe i(community) 
gen sample_tmp3=e(sample)

xtreg obi2_pca_std trt_2 trt_3 wave2 wave3 if sample_tmp3==1 & CuidID==1 & cuid_present_b==1, fe i(community) vce(cluster ID_LOC)	
outreg2 using "Tables/Table 6. Observed Parenting Practices (0-72) 7 practices.xls", replace label dec(2)

foreach var of varlist D6473_std D6574_std D6675_std D6776_std D6879_std D6978_std D7281_std{
	d `var' 
	xtreg `var' trt_2 trt_3 wave2 wave3 if CuidID==1 & cuid_present_b==1, fe i(community) vce(cluster ID_LOC)	
	gen sample_`var'=e(sample)
	count if CuidID==1 & sample_`var'==1 & wave==1   //counting baseline sample size 
	outreg2 using  "Tables/Table 6. Observed Parenting Practices (0-72) 7 practices.xls", append label dec(2)
	}
	
	
***** TOT Analysis *****
xtivreg obi2_pca_std (attended_any2 attended_any3 = trt_2 trt_3) wave2 wave3 if sample_tmp3==1 & CuidID==1 & cuid_present_b==1, fe i(community) vce(cluster ID_LOC)	
outreg2 using "Tables/Table A5. Observed Parenting Practices (0-72) 7 practices_TOT.xls", replace label dec(2)

foreach var of varlist D6473_std D6574_std D6675_std D6776_std D6879_std D6978_std D7281_std{
	d `var' 
	xtivreg `var' (attended_any2 attended_any3 = trt_2 trt_3) wave2 wave3 if CuidID==1 & cuid_present_b==1, fe i(community) vce(cluster ID_LOC)	
	gen sampleTOT_`var'=e(sample)
	count if CuidID==1 & sampleTOT_`var'==1 & wave==1   //counting baseline sample size 
	outreg2 using  "Tables/Table A5. Observed Parenting Practices (0-72) 7 practices_TOT.xls", append label dec(2)
	}
	
*----Generating index regression sample (0-72 months)----*
xtreg D6473 trt_2 trt_3 wave2 wave3 if CuidID==1 & cuid_present_b==1, fe i(community) 
replace sample_tmp3=e(sample)

***** generating regressions by different appendices *****
xtreg obi2_pca_std trt_2 trt_3 wave2 wave3 if sample_tmp3==1 & CuidID==1 & cuid_present_b==1, fe i(community) vce(cluster ID_LOC)
outreg2 using  "Tables/Table A20. Observed Parenting Practices (0-72) 7 practices_alternative indices.xls", replace label dec(2)
xtreg obi2_icw_std trt_2 trt_3 wave2 wave3 if sample_tmp3==1 & CuidID==1 & cuid_present_b==1, fe i(community) vce(cluster ID_LOC)
outreg2 using  "Tables/Table A20. Observed Parenting Practices (0-72) 7 practices_alternative indices.xls", append label dec(2)
xtreg obi2_sw trt_2 trt_3 wave2 wave3 if sample_tmp3==1 & CuidID==1 & cuid_present_b==1, fe i(community) vce(cluster ID_LOC)
outreg2 using  "Tables/Table A20. Observed Parenting Practices (0-72) 7 practices_alternative indices.xls", append label dec(2)
	

*--------------------------------------------*
*                                            *
*       HOME Characteristics Analysis        * 
*                                            *
*--------------------------------------------*
*----Generating and labeling dummies of home characteristics----*
*----0-35 months----*
gen d_p14_cu=(P14_CU>=3) if !missing(P14_CU) 
la var d_p14_cu "[0-3 CASA]Salir de casa más de una vez por semana"
gen d_p15_cu = (P15_CU>1) if !missing(P15_CU) 
la var d_p15_cu "[0-3 CASA]Tiene por lo menos un libro infantil"
gen d_p16_cu = (P16_CU>1) if !missing(P16_CU) 
la var d_p16_cu "[0-3 CASA]Contar cuentos alguna vez por año"
gen d_p17_cu = (P17_CU<=2) if !missing(P17_CU) 
la var d_p17_cu "[0-3 CASA]Llevar al niño al mercado por lo menos una vece por semana"
gen d_p18_cu = (P18_CU>=3) if !missing(P18_CU) 
la var d_p18_cu "[0-3 CASA]Tiene más de dos juguetes como muñecos o peluches"
gen d_p19_cu = (P19_CU>2) if !missing(P19_CU) 
la var d_p19_cu "[0-3 CASA]Tiene más de dos juguetes para empujar"
gen d_p20_cu = (P20_CU==1|P20_CU==3) if !missing(P20_CU) 
la var d_p20_cu "[0-3 CASA]Piensa que los padres deben señar a los niños"
gen d_p24_cu = 2- P24_CU 
la var d_p24_cu "[0-3 CASA]El padre vive con la madre"
gen d_p28_cu = 2- P28_CU
la var d_p28_cu "[0-3 CASA]El niño ve a su figura paterna todos los dias"
gen d_p29_cu = (P29_CU<=2) if !missing(P29_CU) 
la var d_p29_cu "[0-3 CASA]Come con los padres alguna veces por día"
gen d_p30_cu = (P30_CU==1) if !missing(P30_CU) 
la var d_p30_cu "[0-3 CASA] El niño se siente muy apegado a su padre"
gen d_p31_cu = (P31_CU==1) if !missing(P31_CU) 
la var d_p31_cu "[0-3 CASA] Plactica siempre con niños si requieren atención"
gen d_p32_cu = (P32_CU==1) if !missing(P32_CU) 
la var d_p32_cu "[0-3 CASA] El niño se siente muy apegado a su mamá"
*----36-72 months----*
gen d_p34_cu = (P34_CU>=4) if !missing(P34_CU) 
la var d_p34_cu "[3-6 CASA]Contar cuentos por lo menos una vez por semana"
gen d_p35_cu = (P35_CU>=2) if !missing(P35_CU) 
la var d_p35_cu "[3-6 CASA]Tiene algún libro infantil"
gen d_p36_cu = (P36_CU>1) if !missing(P36_CU) 
la var d_p36_cu "[3-6 CASA]Hay revistas en casa"
gen d_37_cu =2-P37_CU
la var d_37_cu "[3-6 CASA]Utiliza aparato para escuchar música"
gen d_37_1_cu =2-P37_1_CU
la var d_37_1_cu "[3-6 CASA]Puede escuchar discos para niños"
gen d_38_1b_cu = 2- P38_1B_CU
replace d_38_1b_cu=. if d_38_1b_cu==-7
la var d_38_1b_cu "[3-6 CASA] Ayuda a los niños a aprender números"
gen d_38_2b_cu = 2- P38_2B_CU
replace d_38_2b_cu=. if d_38_2b_cu==-7
la var d_38_2b_cu "[3-6 CASA] Ayuda a los niños a aprender letras"
gen d_38_3b_cu = 2- P38_3B_CU
replace d_38_3b_cu=. if d_38_3b_cu==-7
la var d_38_3b_cu "[3-6 CASA] Ayuda a los niños a aprender colores"
gen d_38_4b_cu = 2- P38_4B_CU
replace d_38_4b_cu=. if d_38_4b_cu==-7
la var d_38_4b_cu "[3-6 CASA] Ayuda a los niños a aprender formas y tamaños"
gen d_39_cu = (P39_CU<=3) if !missing(P39_CU) 
la var d_39_cu "[3-6 CASA]Permite el niño elijir lo que quiere comer"
gen d_p41_cu = (P41_CU>=5) if !missing(P41_CU) 
la var d_p41_cu "[3-6 CASA]El niño se lleva en alguna salida algunas veces por semana"
gen d_p42_cu = (P41_CU>1) if !missing(P42_CU) 
la var d_p42_cu "[3-6 CASA]El niño se ha llevado al algún lugar histórico en el último año"
gen d_p46_cu = 2- P46_CU if !missing(P46_CU) 
la var d_p46_cu "[3-6 CASA]El padre vive con la madre"
gen d_p50_cu = 2- P50_CU if !missing(P50_CU) 
la var d_p50_cu "[3-6 CASA]El niño ve a su padre todos los días"
gen d_p51_cu = (P51_CU<=2) if !missing(P51_CU) 
la var d_p51_cu "[3-6 CASA]Come con sus padres una vez por días"
gen d_p52_cu = (P52_CU==1) if !missing(P52_CU) 
la var  d_p52_cu "[3-6 CASA]Se siente muy apegado a su padre"
gen d_p53_cu = (P53_CU==1) if !missing(P53_CU) 
la var  d_p53_cu  "[3-6 CASA]Se siente muy apegado a su mamá"
gen d_p54_cu = (P54_CU==1) if !missing(P54_CU) 
la var  d_p54_cu  "[3-6 CASA]Plactica con niños cuando requieren atención"

*--------------------------------*
*----HOME Regression Analysis----*
*--------------------------------*
*----0-35 months----*
*---- Standardizing dummy variables for reported parenting practices----*
foreach var of varlist d_p14_cu d_p15_cu d_p16_cu d_p17_cu d_p18_cu d_p19_cu d_p20_cu P21_CU P21_1_CU P22_CU P22_1_CU P23_CU d_p24_cu d_p28_cu d_p29_cu d_p30_cu d_p31_cu d_p32_cu P33_CU {
sum `var' if ChildID==1  //sum mean and standard error
gen `var'_std=(`var'-r(mean))/r(sd)  //standardizing the scores 
sum `var'_std if ChildID==1  //testing the results 
}

* PCA
pca d_p14_cu_std d_p15_cu_std d_p16_cu_std d_p17_cu_std d_p18_cu_std d_p19_cu_std d_p20_cu_std P21_CU_std P21_1_CU_std P22_CU_std P22_1_CU_std P23_CU_std d_p24_cu_std d_p28_cu_std d_p29_cu_std d_p30_cu_std d_p31_cu_std d_p32_cu_std P33_CU_std if CuidID==1 & cuid_present_b==1
predict obi3_pca, score
sum obi3_pca if ChildID==1  //sum mean and standard error
gen obi3_pca_std=(obi3_pca-r(mean))/r(sd)  //standardizing the scores 
sum obi3_pca_std if ChildID==1  //testing the results 

* ICW
icw_index d_p14_cu_std d_p15_cu_std d_p16_cu_std d_p17_cu_std d_p18_cu_std d_p19_cu_std d_p20_cu_std P21_CU_std P21_1_CU_std P22_CU_std P22_1_CU_std P23_CU_std d_p24_cu_std d_p28_cu_std d_p29_cu_std d_p30_cu_std d_p31_cu_std d_p32_cu_std P33_CU_std, gen(obi3_icw)
sum obi3_icw if ChildID==1  //sum mean and standard error
gen obi3_icw_std=(obi3_icw-r(mean))/r(sd)  //standardizing the scores 
sum obi3_icw_std if ChildID==1  //testing the results 


* SW
swindex d_p14_cu_std d_p15_cu_std d_p16_cu_std d_p17_cu_std d_p18_cu_std d_p19_cu_std d_p20_cu_std P21_CU_std P21_1_CU_std P22_CU_std P22_1_CU_std P23_CU_std d_p24_cu_std d_p28_cu_std d_p29_cu_std d_p30_cu_std d_p31_cu_std d_p32_cu_std P33_CU_std if CuidID==1 & cuid_present_b==1, gen(obi3_sw)


sum obi3_pca_std obi3_icw_std obi3_sw 


***** Table 7: Impact of Reported Parenting Practices (ages 0-35 months) *****

*----Generating index regression sample (0-35 months)----*
xtreg d_p14_cu trt_2 trt_3 wave2 wave3 if CuidID==1 & cuid_present_b==1, fe i(community) 
replace sample_tmp=e(sample)

xtreg obi3_pca_std trt_2 trt_3 wave2 wave3 if sample_tmp==1 & CuidID==1 & cuid_present_b==1, fe i(community) vce(cluster ID_LOC)	
outreg2 using "Tables/Table 7. Reporting Parenting Practices (0-35).xls", replace label dec(2)

foreach var of varlist d_p14_cu_std d_p15_cu_std d_p16_cu_std d_p17_cu_std d_p18_cu_std d_p19_cu_std d_p20_cu_std P21_CU_std P21_1_CU_std P22_CU_std P22_1_CU_std P23_CU_std d_p24_cu_std d_p28_cu_std d_p29_cu_std d_p30_cu_std d_p31_cu_std d_p32_cu_std P33_CU_std {
	d `var'
	xtreg `var' trt_2 trt_3 wave2 wave3 if CuidID==1 & cuid_present_b==1, fe i(community) vce(cluster ID_LOC)
	gen sample_`var'=e(sample)
	count if CuidID==1 & sample_`var'==1& wave==1 //counting baseline sample size 
	outreg2 using "Tables/Table 7. Reporting Parenting Practices (0-35).xls", append label dec(2)
	}
	
***** TOT Analysis *****
xtivreg obi3_pca_std (attended_any2 attended_any3 = trt_2 trt_3) wave2 wave3 if sample_tmp==1 & CuidID==1 & cuid_present_b==1, fe i(community) vce(cluster ID_LOC)	
outreg2 using "Tables/Table A6. Reporting Parenting Practices (0-35)_TOT.xls", replace label dec(2)

foreach var of varlist d_p14_cu_std d_p15_cu_std d_p16_cu_std d_p17_cu_std d_p18_cu_std d_p19_cu_std d_p20_cu_std P21_CU_std P21_1_CU_std P22_CU_std P22_1_CU_std P23_CU_std d_p24_cu_std d_p28_cu_std d_p29_cu_std d_p30_cu_std d_p31_cu_std d_p32_cu_std P33_CU_std {
	d `var'
	xtivreg `var' (attended_any2 attended_any3 = trt_2 trt_3) wave2 wave3 if CuidID==1 & cuid_present_b==1, fe i(community) vce(cluster ID_LOC)
	gen sampleTOT_`var'=e(sample)
	count if CuidID==1 & sample_`var'==1& wave==1 //counting baseline sample size 
	outreg2 using  "Tables/Table A6. Reporting Parenting Practices (0-35)_TOT.xls", append label dec(2)
	}

*----Generating index regression sample (0-72 months)----*
xtreg d_p14_cu trt_2 trt_3 wave2 wave3 if CuidID==1 & cuid_present_b==1, fe i(community) 
replace sample_tmp=e(sample)

*----Comparing across different indices (0-72 months)----*
xtreg obi3_pca_std trt_2 trt_3 wave2 wave3 if sample_tmp==1 & CuidID==1 & cuid_present_b==1, fe i(community) vce(cluster ID_LOC)
outreg2 using  "Tables/Table A21. Reporting Parenting Practices (0-35)_alternative indices.xls", replace label dec(2)
xtreg obi3_icw_std trt_2 trt_3 wave2 wave3 if sample_tmp==1 & CuidID==1 & cuid_present_b==1, fe i(community) vce(cluster ID_LOC)
outreg2 using  "Tables/Table A21. Reporting Parenting Practices (0-35)_alternative indices.xls", append label dec(2)
xtreg obi3_sw trt_2 trt_3 wave2 wave3 if sample_tmp==1 & CuidID==1 & cuid_present_b==1, fe i(community) vce(cluster ID_LOC)
outreg2 using  "Tables/Table A21. Reporting Parenting Practices (0-35)_alternative indices.xls", append label dec(2)

***** Table A7: Impact of Reported Parenting Practices–- Ages 36 - 72 months *****

*----36-72 months----*

* flip for incidence of violence
replace P55_CU = 1 - P55_CU
*---- Standardizing dummy variables for reported parenting practices----*
foreach var of varlist d_p34_cu d_p35_cu d_p36_cu d_37_cu d_37_1_cu d_38_1b_cu d_38_2b_cu d_38_3b_cu d_38_4b_cu d_39_cu d_p41_cu d_p42_cu P43_CU P43_1_CU P44_CU P44_1_CU P45_CU d_p46_cu d_p50_cu d_p51_cu d_p52_cu d_p53_cu d_p54_cu P55_CU {
sum `var' if ChildID==1  //sum mean and standard error
gen `var'_std=(`var'-r(mean))/r(sd)  //standardizing the scores 
sum `var'_std if ChildID==1  //testing the results 
}

* PCA
pca d_p34_cu_std d_p35_cu_std d_p36_cu_std d_37_cu_std d_37_1_cu_std d_38_1b_cu_std d_38_2b_cu_std d_38_3b_cu_std d_38_4b_cu_std d_39_cu_std d_p41_cu_std d_p42_cu_std P43_CU_std P43_1_CU_std P44_CU_std P44_1_CU_std P45_CU_std d_p46_cu_std d_p50_cu_std d_p51_cu_std d_p52_cu_std d_p53_cu_std d_p54_cu_std P55_CU_std if CuidID==1 & cuid_present_b==1
predict obi4_pca, score
sum obi4_pca if ChildID==1  //sum mean and standard error
gen obi4_pca_std=(obi4_pca-r(mean))/r(sd)  //standardizing the scores 
sum obi4_pca_std if ChildID==1  //testing the results 

*----Generating index regression sample (36-72 months)----*
xtreg d_p34_cu_std trt_2 trt_3 wave2 wave3 if CuidID==1 & cuid_present_b==1, fe i(community) 
replace sample_tmp=e(sample)

xtreg obi4_pca_std trt_2 trt_3 wave2 wave3 if sample_tmp==1 & CuidID==1 & cuid_present_b==1, fe i(community) vce(cluster ID_LOC)	
outreg2 using "Tables/Table A7. Reporting Parenting Practices (35-72).xls", replace label dec(2)

foreach var of varlist d_p34_cu_std d_p35_cu_std d_p36_cu_std d_37_cu_std d_37_1_cu_std d_38_1b_cu_std d_38_2b_cu_std d_38_3b_cu_std d_38_4b_cu_std d_39_cu_std d_p41_cu_std d_p42_cu_std P43_CU_std P43_1_CU_std P44_CU_std P44_1_CU_std P45_CU_std d_p46_cu_std d_p50_cu_std d_p51_cu_std d_p52_cu_std d_p53_cu_std d_p54_cu_std P55_CU_std {
	d `var'
	xtreg `var' trt_2 trt_3 wave2 wave3 if CuidID==1 & cuid_present_b==1, fe i(community) vce(cluster ID_LOC)
	gen sample_`var'=e(sample)
	count if CuidID==1 & sample_`var'==1& wave==1 //counting baseline sample size 
	outreg2 using "Tables/Table A7. Reporting Parenting Practices (35-72).xls", append label dec(2)
	}

*-------------------------------------------*
*---------CHILD Attrition regressions-------*
*-------------------------------------------*
***** Table A1: Attrition descriptive statistics (Children) *****
*set-up excel
putexcel set "Tables/Table A1. Attrition.xls", replace
putexcel A2 = "Children"
putexcel A3 = "Year 1"
putexcel A4 = "Year 2"
putexcel A5 = "Caregiver"
putexcel A6 = "Year 1"
putexcel A7 = "Year 2"
putexcel B1 = "Treatment"
putexcel C1 = "Control"
putexcel D1 = "P-value of difference"
putexcel E1 = "Number of observations"


*CHILD Attrition at Year 1*
gen attrit2_asq = 1 - asq_present_2 if wave==1 & ChildID==1  //attrition dummy at year 1
replace attrit2_asq = 1 if missing(attrit2) & wave==1 & ChildID==1
reg attrit2_asq trt if wave==1 & ChildID==1 & asq_present_b ==1 , vce(cluster community)
putexcel C3 = _b[_cons], nformat(number_d2)
putexcel E3 = `e(N)'
putexcel D3 = (r(table)[4,1]), nformat(number_d2)
lincom _cons + trt  //attrition regression at year 1
putexcel B3 = `r(estimate)', nformat(number_d2)


*CHILD Attrition at Year 2*
gen attrit3_asq = 1-asq_present_3 if wave==1 & ChildID==1 //attrition dummy at year 2
replace attrit3_asq = 1 if missing(attrit3) & wave==1 & ChildID==1
reg attrit3_asq trt if wave==1 & ChildID==1 & asq_present_b ==1, vce(cluster community)
putexcel C4 = _b[_cons], nformat(number_d2)
putexcel E4 = `e(N)'
putexcel D4 = (r(table)[4,1]), nformat(number_d2)
lincom _cons + trt  //attrition regression at year 2
putexcel B4 = `r(estimate)', nformat(number_d2)

*--------------------------------------------*
*--------PARENT Attrition regressions--------*
*--------------------------------------------*
**** Table A1: Attrition Regression Analysis (Caregivers) *****
*----PARENT Attrition at Year 1----*
gen attrit2_cuid = 1-cuid_present_2 if wave==1 & CuidID==1
replace attrit2_cuid = 1 if missing(attrit2_cuid) & wave==1 & CuidID==1       //attrition dummy at year 1
reg attrit2_cuid trt if wave==1 & CuidID==1 & cuid_present_b ==1 , vce(cluster community)
putexcel C6 = _b[_cons], nformat(number_d2)
putexcel E6 = `e(N)'
putexcel D6 = (r(table)[4,1]), nformat(number_d2)
lincom _cons + trt                //attrition regression at year 1
putexcel B6 = `r(estimate)', nformat(number_d2)

*----PARENT Attrition at Year 2----*
gen attrit3_cuid = 1-cuid_present_3 if wave==1 & CuidID==1
replace attrit3_cuid = 1 if missing(attrit3_cuid) & wave==1 & CuidID==1 //attrition dummy at year 2 
reg attrit3_cuid trt if wave==1 & CuidID==1 & cuid_present_b ==1, vce(cluster community)
putexcel C7 = _b[_cons], nformat(number_d2)
putexcel E7 = `e(N)'
putexcel D7 = (r(table)[4,1]), nformat(number_d2)
lincom _cons + trt //attrition regression at year 2
putexcel B7 = `r(estimate)', nformat(number_d2)

*-----------------------------------------------*
*                                               *
*    Robusteness Check I:Implementation Mode    * 
*                                               *
*-----------------------------------------------*
//Note: This part is a robustness check regarding potential biased reporting 
//scores. The analysis includes a statistitical description and a regression.
*---------------------------------*
*----Implementation Statistics----*
*---------------------------------*
*----Generating variables of each implementation mode: A-reported; B-judged; C-observed*
{
***2 MESES***
gen ASQ_A= SCOM_01 + SCOM_02 + SCOM_03+ SCOM_04+ SCOM_06+SMOTG_01+ SMOTG_05+SMOTF_04+ SMOTF_06+SSOCI_01+ SSOCI_02+ SSOCI_03+ SSOCI_04+ SSOCI_06 if cuest==2
gen avg_A= ASQ_A/14 if cuest==2
gen ASQ_B = SCOM_05+ SMOTG_02+ SMOTG_03+SMOTG_04+SMOTF_01+ SMOTF_05+SRESP_02+SSOCI_05 if cuest==2
gen avg_B = ASQ_B/8 if cuest==2
gen ASQ_C = SMOTG_06+SMOTF_02 + SMOTF_03+SRESP_01+SRESP_03+SRESP_04+SRESP_05+SRESP_06 if cuest==2
gen avg_C = ASQ_C/8 if cuest==2

***4 MESES***
replace ASQ_A= SCOM_03+ SCOM_04+ SCOM_05+SMOTF_03+SRESP_04 + SRESP_05+SSOCI_01+ SSOCI_03+ SSOCI_05 if cuest==4
replace avg_A= ASQ_A/9 if cuest==4
replace ASQ_B = SCOM_01 + SCOM_02+ SCOM_06+ SMOTG_01+ SMOTG_05+SMOTG_06+ SMOTF_01+ SMOTF_04 +SMOTF_06+SSOCI_02+SSOCI_04+SSOCI_06 if cuest==4
replace avg_B = ASQ_B/12 if cuest==4
replace ASQ_C = SMOTG_02 + SMOTG_03+ SMOTG_04+SMOTF_02 + SMOTF_05+SRESP_01+SRESP_02+SRESP_03+SRESP_06 if cuest==4
replace avg_C = ASQ_C/9 if cuest==4

***6 MESES***
replace ASQ_A= SCOM_01+ SCOM_02+ SCOM_04+ SCOM_05 + SMOTG_03 + SMOTG_06 + SMOTF_02+ SRESP_02 + SRESP_03+ SRESP_04+ SSOCI_02+ SSOCI_03+ SSOCI_05 +SSOCI_06 if cuest ==6
replace avg_A= ASQ_A/14 if cuest==6
replace ASQ_B =SCOM_03 + SCOM_06+ SMOTG_01+ SMOTG_02+SMOTG_05+SMOTF_01+SRESP_05 + SRESP_06+SSOCI_01 + SSOCI_04 if cuest==6
replace avg_B = ASQ_B/10 if cuest==6
replace ASQ_C = SMOTG_04 +SMOTF_03 + SMOTF_04+SMOTF_05+SMOTF_06 +SRESP_01  if cuest==6
replace avg_C = ASQ_C/6 if cuest==6

***8 MESES***
gen ASQ_COM_A = SCOM_01+ SCOM_02+ SCOM_03+ SCOM_04 if cuest ==8
gen ASQ_COM_B = SCOM_05 + SCOM_06 if cuest==8
gen ASQ_COM_C = 0 if cuest==8

gen ASQ_MOTG_A = SMOTG_02 + SMOTG_03 +SMOTG_05 if cuest ==8
gen ASQ_MOTG_B = SMOTG_04+ SMOTG_06 if cuest==8
gen ASQ_MOTG_C = SMOTG_01 if cuest==8

gen ASQ_MOTF_A = 0 if cuest ==8
gen ASQ_MOTF_B = 0 if cuest==8
gen ASQ_MOTF_C = SMOTF_01+SMOTF_02+SMOTF_03+ SMOTF_04+SMOTF_05+SMOTF_06 if cuest==8

gen ASQ_RESP_A = 0 if cuest ==8
gen ASQ_RESP_B = 0 if cuest==8
gen ASQ_RESP_C = SRESP_01+SRESP_02+SRESP_03+SRESP_04+SRESP_05+SRESP_06 if cuest==8

gen ASQ_SOCI_A = SSOCI_05 +SSOCI_06 if cuest==8
gen ASQ_SOCI_B = SSOCI_01 + SSOCI_02+ SSOCI_04  if cuest==8
gen ASQ_SOCI_C = SSOCI_03 if cuest==8

replace ASQ_A= ASQ_COM_A+ASQ_MOTG_A+ASQ_MOTF_A+ASQ_RESP_A+ASQ_SOCI_A if cuest==8
replace avg_A= ASQ_A/9 if cuest==8
replace ASQ_B =ASQ_COM_B+ASQ_MOTG_B+ASQ_MOTF_B+ASQ_RESP_B+ASQ_SOCI_B if cuest==8
replace avg_B = ASQ_B/7 if cuest==8
replace ASQ_C =ASQ_COM_C+ASQ_MOTG_C+ASQ_MOTF_C+ASQ_RESP_C+ASQ_SOCI_C if cuest==8
replace avg_C = ASQ_C/14 if cuest==8

***10 MESES***

replace ASQ_COM_A = SCOM_04+ SCOM_05+ SCOM_06 if cuest ==10
replace ASQ_COM_B = SCOM_01 + SCOM_02 +SCOM_03 if cuest==10
replace ASQ_COM_C = 0 if cuest==10

replace ASQ_MOTG_A = 0 if cuest ==10
replace ASQ_MOTG_B = SMOTG_03+ SMOTG_04+SMOTG_05+SMOTG_06 if cuest==10
replace ASQ_MOTG_C = SMOTG_01+SMOTG_02 if cuest==10

replace ASQ_MOTF_A = 0 if cuest ==10
replace ASQ_MOTF_B = 0 if cuest==10
replace ASQ_MOTF_C = SMOTF_01+SMOTF_02+SMOTF_03+ SMOTF_04+SMOTF_05+SMOTF_06 if cuest==10

replace ASQ_RESP_A = 0 if cuest ==10
replace ASQ_RESP_B = 0 if cuest==10
replace ASQ_RESP_C = SRESP_01+SRESP_02+SRESP_03+SRESP_04+SRESP_05+SRESP_06 if cuest==10

replace ASQ_SOCI_A = SSOCI_01+SSOCI_05 +SSOCI_06 if cuest==10
replace ASQ_SOCI_B = SSOCI_02 + SSOCI_03+ SSOCI_04  if cuest==10
replace ASQ_SOCI_C = 0 if cuest==10

replace ASQ_A= ASQ_COM_A+ASQ_MOTG_A+ASQ_MOTF_A+ASQ_RESP_A+ASQ_SOCI_A if cuest==10
replace avg_A= ASQ_A/6 if cuest==10
replace ASQ_B =ASQ_COM_B+ASQ_MOTG_B+ASQ_MOTF_B+ASQ_RESP_B+ASQ_SOCI_B if cuest==10
replace avg_B = ASQ_B/10 if cuest==10
replace ASQ_C =ASQ_COM_C+ASQ_MOTG_C+ASQ_MOTF_C+ASQ_RESP_C+ASQ_SOCI_C if cuest==10
replace avg_C = ASQ_C/14 if cuest==10

***12 MESES***
replace ASQ_COM_A = SCOM_02+ SCOM_03 if cuest ==12
replace ASQ_COM_B = SCOM_01 + SCOM_04 if cuest==12
replace ASQ_COM_C = SCOM_05 + SCOM_06 if cuest==12

replace ASQ_MOTG_A = 0 if cuest ==12
replace ASQ_MOTG_B = SMOTG_01+ SMOTG_02+SMOTG_03+SMOTG_06 if cuest==12
replace ASQ_MOTG_C = SMOTG_04+SMOTG_05 if cuest==12

replace ASQ_MOTF_A = 0 if cuest ==12
replace ASQ_MOTF_B = 0 if cuest==12
replace ASQ_MOTF_C = SMOTF_01+SMOTF_02+SMOTF_03+ SMOTF_04+SMOTF_05+SMOTF_06 if cuest==12

replace ASQ_RESP_A = 0 if cuest ==12
replace ASQ_RESP_B = 0 if cuest==12
replace ASQ_RESP_C = SRESP_01+SRESP_02+SRESP_03+SRESP_04+SRESP_05+SRESP_06 if cuest==12

replace ASQ_SOCI_A = SSOCI_01+SSOCI_02 +SSOCI_06 if cuest==12
replace ASQ_SOCI_B = SSOCI_03 + SSOCI_04+ SSOCI_05  if cuest==12
replace ASQ_SOCI_C = 0 if cuest==12

replace ASQ_A= ASQ_COM_A+ASQ_MOTG_A+ASQ_MOTF_A+ASQ_RESP_A+ASQ_SOCI_A if cuest==12
replace avg_A= ASQ_A/5 if cuest==12
replace ASQ_B =ASQ_COM_B+ASQ_MOTG_B+ASQ_MOTF_B+ASQ_RESP_B+ASQ_SOCI_B if cuest==12
replace avg_B = ASQ_B/9 if cuest==12
replace ASQ_C =ASQ_COM_C+ASQ_MOTG_C+ASQ_MOTF_C+ASQ_RESP_C+ASQ_SOCI_C if cuest==12
replace avg_C = ASQ_C/16 if cuest==12

***14 MESES***

replace ASQ_COM_A = SCOM_01+SCOM_02+ SCOM_03+SCOM_05 if cuest ==14
replace ASQ_COM_B = 0 if cuest==14
replace ASQ_COM_C = SCOM_04 + SCOM_06 if cuest==14

replace ASQ_MOTG_A = SMOTG_03+SMOTG_06 if cuest ==14
replace ASQ_MOTG_B = SMOTG_04+SMOTG_05 if cuest==14
replace ASQ_MOTG_C = SMOTG_01+SMOTG_02 if cuest==14

replace ASQ_MOTF_A = 0 if cuest ==14
replace ASQ_MOTF_B = SMOTF_03 if cuest==14
replace ASQ_MOTF_C = SMOTF_01+SMOTF_02+ SMOTF_04+SMOTF_05+SMOTF_06 if cuest==14

replace ASQ_RESP_A = 0 if cuest ==14
replace ASQ_RESP_B = 0 if cuest==14
replace ASQ_RESP_C = SRESP_01+SRESP_02+SRESP_03+SRESP_04+SRESP_05+SRESP_06 if cuest==14

replace ASQ_SOCI_A = SSOCI_03+SSOCI_05 +SSOCI_06 if cuest==14
replace ASQ_SOCI_B = SSOCI_01 + SSOCI_02+ SSOCI_04  if cuest==14
replace ASQ_SOCI_C = 0 if cuest==14

replace ASQ_A= ASQ_COM_A+ASQ_MOTG_A+ASQ_MOTF_A+ASQ_RESP_A+ASQ_SOCI_A if cuest==14
replace avg_A= ASQ_A/9 if cuest==14
replace ASQ_B =ASQ_COM_B+ASQ_MOTG_B+ASQ_MOTF_B+ASQ_RESP_B+ASQ_SOCI_B if cuest==14
replace avg_B = ASQ_B/6 if cuest==14
replace ASQ_C =ASQ_COM_C+ASQ_MOTG_C+ASQ_MOTF_C+ASQ_RESP_C+ASQ_SOCI_C if cuest==14
replace avg_C = ASQ_C/15 if cuest==14

***16 MESES***
replace ASQ_COM_A = SCOM_03 if cuest ==16
replace ASQ_COM_B = 0 if cuest==16
replace ASQ_COM_C = SCOM_01+SCOM_02+SCOM_04+SCOM_05+SCOM_06 if cuest==16

replace ASQ_MOTG_A = SMOTG_04+SMOTG_05 if cuest ==16
replace ASQ_MOTG_B = SMOTG_02+SMOTG_03+SMOTG_06 if cuest==16
replace ASQ_MOTG_C = SMOTG_01 if cuest==16

replace ASQ_MOTF_A = 0 if cuest ==16
replace ASQ_MOTF_B = SMOTF_03 if cuest==16
replace ASQ_MOTF_C = SMOTF_01+SMOTF_02+ SMOTF_04+SMOTF_05+SMOTF_06 if cuest==16

replace ASQ_RESP_A = 0 if cuest ==16
replace ASQ_RESP_B = 0 if cuest==16
replace ASQ_RESP_C = SRESP_01+SRESP_02+SRESP_03+SRESP_04+SRESP_05+SRESP_06 if cuest==16

replace ASQ_SOCI_A = SSOCI_01+SSOCI_02+SSOCI_05 +SSOCI_06 if cuest==16
replace ASQ_SOCI_B = SSOCI_03 + SSOCI_04  if cuest==16
replace ASQ_SOCI_C = 0 if cuest==16

replace ASQ_A= ASQ_COM_A+ASQ_MOTG_A+ASQ_MOTF_A+ASQ_RESP_A+ASQ_SOCI_A if cuest==16
replace avg_A= ASQ_A/7 if cuest==16
replace ASQ_B =ASQ_COM_B+ASQ_MOTG_B+ASQ_MOTF_B+ASQ_RESP_B+ASQ_SOCI_B if cuest==16
replace avg_B = ASQ_B/6 if cuest==16
replace ASQ_C =ASQ_COM_C+ASQ_MOTG_C+ASQ_MOTF_C+ASQ_RESP_C+ASQ_SOCI_C if cuest==16
replace avg_C = ASQ_C/17 if cuest==16

***18 MESES***
replace ASQ_COM_A = SCOM_01+SCOM_02+SCOM_04+SCOM_06 if cuest ==18
replace ASQ_COM_B = SCOM_03 if cuest==18
replace ASQ_COM_C = SCOM_05 if cuest==18

replace ASQ_MOTG_A = SMOTG_02+SMOTG_03 if cuest ==18
replace ASQ_MOTG_B = SMOTG_04+SMOTG_05 if cuest==18
replace ASQ_MOTG_C = SMOTG_01+SMOTG_06 if cuest==18

replace ASQ_MOTF_A = 0 if cuest ==18
replace ASQ_MOTF_B = SMOTF_03 if cuest==18
replace ASQ_MOTF_C = SMOTF_01+SMOTF_02+ SMOTF_04+SMOTF_05+SMOTF_06 if cuest==18

replace ASQ_RESP_A = 0 if cuest ==18
replace ASQ_RESP_B = 0 if cuest==18
replace ASQ_RESP_C = SRESP_01+SRESP_02+SRESP_03+SRESP_04+SRESP_05+SRESP_06 if cuest==18

replace ASQ_SOCI_A = SSOCI_02+SSOCI_03+SSOCI_04+SSOCI_05 +SSOCI_06 if cuest==18
replace ASQ_SOCI_B = SSOCI_01 if cuest==18
replace ASQ_SOCI_C = 0 if cuest==18

replace ASQ_A= ASQ_COM_A+ASQ_MOTG_A+ASQ_MOTF_A+ASQ_RESP_A+ASQ_SOCI_A if cuest==18
replace avg_A= ASQ_A/11 if cuest==18
replace ASQ_B =ASQ_COM_B+ASQ_MOTG_B+ASQ_MOTF_B+ASQ_RESP_B+ASQ_SOCI_B if cuest==18
replace avg_B = ASQ_B/5 if cuest==18
replace ASQ_C =ASQ_COM_C+ASQ_MOTG_C+ASQ_MOTF_C+ASQ_RESP_C+ASQ_SOCI_C if cuest==18
replace avg_C = ASQ_C/14 if cuest==18

***20 MESES***
replace ASQ_COM_A = SCOM_01 if cuest ==20
replace ASQ_COM_B = SCOM_02+SCOM_06 if cuest==20
replace ASQ_COM_C = SCOM_03+SCOM_04+SCOM_05 if cuest==20

replace ASQ_MOTG_A = SMOTG_02 if cuest ==20
replace ASQ_MOTG_B = SMOTG_01+SMOTG_03+SMOTG_05 if cuest==20
replace ASQ_MOTG_C = SMOTG_04+SMOTG_06 if cuest==20

replace ASQ_MOTF_A = SMOTF_04 if cuest ==20
replace ASQ_MOTF_B = SMOTF_03 if cuest==20
replace ASQ_MOTF_C = SMOTF_01+SMOTF_02+ SMOTF_05+SMOTF_06 if cuest==20

replace ASQ_RESP_A = 0 if cuest ==20
replace ASQ_RESP_B = SRESP_04+SRESP_06 if cuest==20
replace ASQ_RESP_C = SRESP_01+SRESP_02+SRESP_03+SRESP_05 if cuest==20

replace ASQ_SOCI_A = SSOCI_01+SSOCI_02+SSOCI_03+SSOCI_06 if cuest==20
replace ASQ_SOCI_B = SSOCI_04+SSOCI_05 if cuest==20
replace ASQ_SOCI_C = 0 if cuest==20

replace ASQ_A= ASQ_COM_A+ASQ_MOTG_A+ASQ_MOTF_A+ASQ_RESP_A+ASQ_SOCI_A if cuest==20
replace avg_A= ASQ_A/7 if cuest==20
replace ASQ_B =ASQ_COM_B+ASQ_MOTG_B+ASQ_MOTF_B+ASQ_RESP_B+ASQ_SOCI_B if cuest==20
replace avg_B = ASQ_B/10 if cuest==20
replace ASQ_C =ASQ_COM_C+ASQ_MOTG_C+ASQ_MOTF_C+ASQ_RESP_C+ASQ_SOCI_C if cuest==20
replace avg_C = ASQ_C/13 if cuest==20

***22 MESES***
replace ASQ_COM_A = 0 if cuest ==22
replace ASQ_COM_B = SCOM_04+SCOM_05+SCOM_06 if cuest==22
replace ASQ_COM_C = SCOM_01+SCOM_02+SCOM_03 if cuest==22

replace ASQ_MOTG_A = SMOTG_02 if cuest ==22
replace ASQ_MOTG_B = SMOTG_03+SMOTG_04 if cuest==22
replace ASQ_MOTG_C = SMOTG_01+SMOTG_05+SMOTG_06 if cuest==22

replace ASQ_MOTF_A = 0 if cuest ==22
replace ASQ_MOTF_B = SMOTF_01+SMOTF_05 if cuest==22
replace ASQ_MOTF_C = SMOTF_02+SMOTF_03+ SMOTF_04+SMOTF_06 if cuest==22

replace ASQ_RESP_A = 0 if cuest ==22
replace ASQ_RESP_B = SRESP_03+SRESP_06 if cuest==22
replace ASQ_RESP_C = SRESP_01+SRESP_02+SRESP_04+SRESP_05 if cuest==22

replace ASQ_SOCI_A = SSOCI_03+SSOCI_04 if cuest==22
replace ASQ_SOCI_B = SSOCI_01+SSOCI_05+SSOCI_06 if cuest==22
replace ASQ_SOCI_C = SSOCI_02 if cuest==22

replace ASQ_A= ASQ_COM_A+ASQ_MOTG_A+ASQ_MOTF_A+ASQ_RESP_A+ASQ_SOCI_A if cuest==22
replace avg_A= ASQ_A/3 if cuest==22
replace ASQ_B =ASQ_COM_B+ASQ_MOTG_B+ASQ_MOTF_B+ASQ_RESP_B+ASQ_SOCI_B if cuest==22
replace avg_B = ASQ_B/12 if cuest==22
replace ASQ_C =ASQ_COM_C+ASQ_MOTG_C+ASQ_MOTF_C+ASQ_RESP_C+ASQ_SOCI_C if cuest==22
replace avg_C = ASQ_C/15 if cuest==22

***24 MESES***
replace ASQ_COM_A = 0 if cuest ==24
replace ASQ_COM_B = SCOM_02+SCOM_05+SCOM_06 if cuest==24
replace ASQ_COM_C = SCOM_01+SCOM_03+SCOM_04 if cuest==24

replace ASQ_MOTG_A = SMOTG_04 if cuest ==24
replace ASQ_MOTG_B = SMOTG_01+SMOTG_03 if cuest==24
replace ASQ_MOTG_C = SMOTG_02+SMOTG_05+SMOTG_06 if cuest==24

replace ASQ_MOTF_A = SMOTF_01 if cuest ==24
replace ASQ_MOTF_B = SMOTF_02+SMOTF_04 if cuest==24
replace ASQ_MOTF_C = SMOTF_03+SMOTF_05+ SMOTF_06 if cuest==24

replace ASQ_RESP_A =SRESP_04  if cuest ==24
replace ASQ_RESP_B = SRESP_03+SRESP_05 if cuest==24
replace ASQ_RESP_C = SRESP_01+SRESP_02+SRESP_06 if cuest==24

replace ASQ_SOCI_A = SSOCI_01+SSOCI_02+SSOCI_03 if cuest==24
replace ASQ_SOCI_B = SSOCI_04+SSOCI_05+SSOCI_06 if cuest==24
replace ASQ_SOCI_C = 0 if cuest==24

replace ASQ_A= ASQ_COM_A+ASQ_MOTG_A+ASQ_MOTF_A+ASQ_RESP_A+ASQ_SOCI_A if cuest==24
replace avg_A= ASQ_A/6 if cuest==24
replace ASQ_B =ASQ_COM_B+ASQ_MOTG_B+ASQ_MOTF_B+ASQ_RESP_B+ASQ_SOCI_B if cuest==24
replace avg_B = ASQ_B/12 if cuest==24
replace ASQ_C =ASQ_COM_C+ASQ_MOTG_C+ASQ_MOTF_C+ASQ_RESP_C+ASQ_SOCI_C if cuest==24
replace avg_C = ASQ_C/12 if cuest==24

***27 MESES***
replace ASQ_COM_A = 0 if cuest ==27
replace ASQ_COM_B = SCOM_04+SCOM_05 if cuest==27
replace ASQ_COM_C = SCOM_01+SCOM_02+SCOM_03+SCOM_06 if cuest==27

replace ASQ_MOTG_A = SMOTG_02 if cuest ==27
replace ASQ_MOTG_B = SMOTG_01+SMOTG_06 if cuest==27
replace ASQ_MOTG_C = SMOTG_03+SMOTG_04+SMOTG_05 if cuest==27

replace ASQ_MOTF_A = 0 if cuest ==27
replace ASQ_MOTF_B = SMOTF_02 if cuest==27
replace ASQ_MOTF_C = SMOTF_01+SMOTF_03+SMOTF_04+SMOTF_05+ SMOTF_06 if cuest==27

replace ASQ_RESP_A =SRESP_02  if cuest ==27
replace ASQ_RESP_B = SRESP_01+SRESP_04 if cuest==27
replace ASQ_RESP_C = SRESP_03+SRESP_05+SRESP_06 if cuest==27

replace ASQ_SOCI_A = SSOCI_02+SSOCI_05+SSOCI_06 if cuest==27
replace ASQ_SOCI_B = SSOCI_03+SSOCI_04 if cuest==27
replace ASQ_SOCI_C = SSOCI_01 if cuest==27

replace ASQ_A= ASQ_COM_A+ASQ_MOTG_A+ASQ_MOTF_A+ASQ_RESP_A+ASQ_SOCI_A if cuest==27
replace avg_A= ASQ_A/5 if cuest==27
replace ASQ_B =ASQ_COM_B+ASQ_MOTG_B+ASQ_MOTF_B+ASQ_RESP_B+ASQ_SOCI_B if cuest==27
replace avg_B = ASQ_B/9 if cuest==27
replace ASQ_C =ASQ_COM_C+ASQ_MOTG_C+ASQ_MOTF_C+ASQ_RESP_C+ASQ_SOCI_C if cuest==27
replace avg_C = ASQ_C/16 if cuest==27

***30 MESES***
replace ASQ_COM_A = 0 if cuest ==30
replace ASQ_COM_B = SCOM_04 if cuest==30
replace ASQ_COM_C = SCOM_01+SCOM_02+SCOM_03+SCOM_05+SCOM_06 if cuest==30

replace ASQ_MOTG_A = SMOTG_01 if cuest ==30
replace ASQ_MOTG_B = SMOTG_02+SMOTG_05 if cuest==30
replace ASQ_MOTG_C = SMOTG_03+SMOTG_04+SMOTG_06 if cuest==30

replace ASQ_MOTF_A = 0 if cuest ==30
replace ASQ_MOTF_B = SMOTF_06 if cuest==30
replace ASQ_MOTF_C = SMOTF_01+SMOTF_02+SMOTF_03+SMOTF_04+ SMOTF_05 if cuest==30

replace ASQ_RESP_A =0  if cuest ==30
replace ASQ_RESP_B = SRESP_02 if cuest==30
replace ASQ_RESP_C = SRESP_01+SRESP_03+SRESP_04+SRESP_05+SRESP_06 if cuest==30

replace ASQ_SOCI_A = SSOCI_02+SSOCI_04 if cuest==30
replace ASQ_SOCI_B = SSOCI_03+SSOCI_05 if cuest==30
replace ASQ_SOCI_C = SSOCI_01+SSOCI_06 if cuest==30

replace ASQ_A= ASQ_COM_A+ASQ_MOTG_A+ASQ_MOTF_A+ASQ_RESP_A+ASQ_SOCI_A if cuest==30
replace avg_A= ASQ_A/3 if cuest==30
replace ASQ_B =ASQ_COM_B+ASQ_MOTG_B+ASQ_MOTF_B+ASQ_RESP_B+ASQ_SOCI_B if cuest==30
replace avg_B = ASQ_B/7 if cuest==30
replace ASQ_C =ASQ_COM_C+ASQ_MOTG_C+ASQ_MOTF_C+ASQ_RESP_C+ASQ_SOCI_C if cuest==30
replace avg_C = ASQ_C/20 if cuest==30

***33 MESES***
replace ASQ_COM_A = 0 if cuest ==33
replace ASQ_COM_B = SCOM_02 if cuest==33
replace ASQ_COM_C = SCOM_01+SCOM_03+SCOM_04+SCOM_05+SCOM_06 if cuest==33

replace ASQ_MOTG_A = SMOTG_01 if cuest ==33
replace ASQ_MOTG_B = SMOTG_04 if cuest==33
replace ASQ_MOTG_C = SMOTG_02+SMOTG_03+SMOTG_05+SMOTG_06 if cuest==33

replace ASQ_MOTF_A = 0 if cuest ==33
replace ASQ_MOTF_B = SMOTF_05 if cuest==33
replace ASQ_MOTF_C = SMOTF_01+SMOTF_02+SMOTF_03+SMOTF_04+ SMOTF_06 if cuest==33

replace ASQ_RESP_A =0  if cuest ==33
replace ASQ_RESP_B = SRESP_03 if cuest==33
replace ASQ_RESP_C = SRESP_01+SRESP_02+SRESP_04+SRESP_05+SRESP_06 if cuest==33

replace ASQ_SOCI_A = SSOCI_01+SSOCI_03 if cuest==33
replace ASQ_SOCI_B = SSOCI_02+SSOCI_04 if cuest==33
replace ASQ_SOCI_C = SSOCI_05+SSOCI_06 if cuest==33

replace ASQ_A= ASQ_COM_A+ASQ_MOTG_A+ASQ_MOTF_A+ASQ_RESP_A+ASQ_SOCI_A if cuest==33
replace avg_A= ASQ_A/3 if cuest==33
replace ASQ_B =ASQ_COM_B+ASQ_MOTG_B+ASQ_MOTF_B+ASQ_RESP_B+ASQ_SOCI_B if cuest==33
replace avg_B = ASQ_B/6 if cuest==33
replace ASQ_C =ASQ_COM_C+ASQ_MOTG_C+ASQ_MOTF_C+ASQ_RESP_C+ASQ_SOCI_C if cuest==33
replace avg_C = ASQ_C/21 if cuest==33

***36 MESES***
replace ASQ_COM_A = 0 if cuest ==36
replace ASQ_COM_B = SCOM_02 if cuest==36
replace ASQ_COM_C = SCOM_01+SCOM_03+SCOM_04+SCOM_05+SCOM_06 if cuest==36

replace ASQ_MOTG_A = 0 if cuest ==36
replace ASQ_MOTG_B = SMOTG_03 if cuest==36
replace ASQ_MOTG_C = SMOTG_01+SMOTG_02+SMOTG_04+SMOTG_05+SMOTG_06 if cuest==36

replace ASQ_MOTF_A = 0 if cuest ==36
replace ASQ_MOTF_B = 0 if cuest==36
replace ASQ_MOTF_C = SMOTF_01+SMOTF_02+SMOTF_03+SMOTF_04+SMOTF_05+SMOTF_06 if cuest==36

replace ASQ_RESP_A =0  if cuest ==36
replace ASQ_RESP_B = SRESP_02 if cuest==36
replace ASQ_RESP_C = SRESP_01+SRESP_03+SRESP_04+SRESP_05+SRESP_06 if cuest==36

replace ASQ_SOCI_A = SSOCI_01+SSOCI_04 +SSOCI_06 if cuest==36
replace ASQ_SOCI_B = SSOCI_02 if cuest==36
replace ASQ_SOCI_C = SSOCI_03+SSOCI_05 if cuest==36

replace ASQ_A= ASQ_COM_A+ASQ_MOTG_A+ASQ_MOTF_A+ASQ_RESP_A+ASQ_SOCI_A if cuest==36
replace avg_A= ASQ_A/3 if cuest==36
replace ASQ_B =ASQ_COM_B+ASQ_MOTG_B+ASQ_MOTF_B+ASQ_RESP_B+ASQ_SOCI_B if cuest==36
replace avg_B = ASQ_B/4 if cuest==36
replace ASQ_C =ASQ_COM_C+ASQ_MOTG_C+ASQ_MOTF_C+ASQ_RESP_C+ASQ_SOCI_C if cuest==36
replace avg_C = ASQ_C/23 if cuest==36

***42 MESES***
replace ASQ_COM_A = 0 if cuest ==42
replace ASQ_COM_B = SCOM_06 if cuest==42
replace ASQ_COM_C = SCOM_01+SCOM_02+SCOM_03+SCOM_04+SCOM_05 if cuest==42

replace ASQ_MOTG_A = 0 if cuest ==42
replace ASQ_MOTG_B = SMOTG_01+SMOTG_06 if cuest==42
replace ASQ_MOTG_C = SMOTG_02+SMOTG_03+SMOTG_04+SMOTG_05 if cuest==42

replace ASQ_MOTF_A = 0 if cuest ==42
replace ASQ_MOTF_B = 0 if cuest==42
replace ASQ_MOTF_C = SMOTF_01+SMOTF_02+SMOTF_03+SMOTF_04+SMOTF_05+SMOTF_06 if cuest==42

replace ASQ_RESP_A = SRESP_06 if cuest ==42
replace ASQ_RESP_B = 0 if cuest==42
replace ASQ_RESP_C = SRESP_01+SRESP_02+SRESP_03+SRESP_04+SRESP_05 if cuest==42

replace ASQ_SOCI_A = SSOCI_02+SSOCI_04+SSOCI_05+SSOCI_06 if cuest==42
replace ASQ_SOCI_B = 0 if cuest==42
replace ASQ_SOCI_C = SSOCI_01+SSOCI_03 if cuest==42

replace ASQ_A= ASQ_COM_A+ASQ_MOTG_A+ASQ_MOTF_A+ASQ_RESP_A+ASQ_SOCI_A if cuest==42
replace avg_A= ASQ_A/5 if cuest==42
replace ASQ_B =ASQ_COM_B+ASQ_MOTG_B+ASQ_MOTF_B+ASQ_RESP_B+ASQ_SOCI_B if cuest==42
replace avg_B = ASQ_B/3 if cuest==42
replace ASQ_C =ASQ_COM_C+ASQ_MOTG_C+ASQ_MOTF_C+ASQ_RESP_C+ASQ_SOCI_C if cuest==42
replace avg_C = ASQ_C/22 if cuest==42

***48 MESES***
replace ASQ_COM_A = 0 if cuest ==48
replace ASQ_COM_B = SCOM_06 if cuest==48
replace ASQ_COM_C = SCOM_01+SCOM_02+SCOM_03+SCOM_04+SCOM_05 if cuest==48

replace ASQ_MOTG_A = 0 if cuest ==48
replace ASQ_MOTG_B = SMOTG_02 if cuest==48
replace ASQ_MOTG_C = SMOTG_01+SMOTG_03+SMOTG_04+SMOTG_05+SMOTG_06 if cuest==48

replace ASQ_MOTF_A = 0 if cuest ==48
replace ASQ_MOTF_B = SMOTF_04 if cuest==48
replace ASQ_MOTF_C = SMOTF_01+SMOTF_02+SMOTF_03+SMOTF_05+SMOTF_06 if cuest==48

replace ASQ_RESP_A = SRESP_05 if cuest ==48
replace ASQ_RESP_B = 0 if cuest==48
replace ASQ_RESP_C = SRESP_01+SRESP_02+SRESP_03+SRESP_04+SRESP_06 if cuest==48

replace ASQ_SOCI_A = SSOCI_01+SSOCI_03+SSOCI_05+SSOCI_06 if cuest==48
replace ASQ_SOCI_B = 0 if cuest==48
replace ASQ_SOCI_C = SSOCI_02+SSOCI_04 if cuest==48

replace ASQ_A= ASQ_COM_A+ASQ_MOTG_A+ASQ_MOTF_A+ASQ_RESP_A+ASQ_SOCI_A if cuest==48
replace avg_A= ASQ_A/5 if cuest==48
replace ASQ_B =ASQ_COM_B+ASQ_MOTG_B+ASQ_MOTF_B+ASQ_RESP_B+ASQ_SOCI_B if cuest==48
replace avg_B = ASQ_B/3 if cuest==48
replace ASQ_C =ASQ_COM_C+ASQ_MOTG_C+ASQ_MOTF_C+ASQ_RESP_C+ASQ_SOCI_C if cuest==48
replace avg_C = ASQ_C/22 if cuest==48

***54 MESES***
replace ASQ_COM_A = 0 if cuest ==54
replace ASQ_COM_B = SCOM_02+SCOM_03+SCOM_05 if cuest==54
replace ASQ_COM_C = SCOM_01+SCOM_04+SCOM_06 if cuest==54

replace ASQ_MOTG_A = 0 if cuest ==54
replace ASQ_MOTG_B = 0 if cuest==54
replace ASQ_MOTG_C = SMOTG_01+SMOTG_02+SMOTG_03+SMOTG_04+SMOTG_05+SMOTG_06 if cuest==54

replace ASQ_MOTF_A = 0 if cuest ==54
replace ASQ_MOTF_B = SMOTF_02 if cuest==54
replace ASQ_MOTF_C = SMOTF_01+SMOTF_03+SMOTF_04+SMOTF_05+SMOTF_06 if cuest==54

replace ASQ_RESP_A = SRESP_02 if cuest ==54
replace ASQ_RESP_B = 0 if cuest==54
replace ASQ_RESP_C = SRESP_01+SRESP_03+SRESP_04+SRESP_05+SRESP_06 if cuest==54

replace ASQ_SOCI_A = SSOCI_01+SSOCI_03+SSOCI_04+SSOCI_06 if cuest==54
replace ASQ_SOCI_B = 0 if cuest==54
replace ASQ_SOCI_C = SSOCI_02+SSOCI_05 if cuest==54

replace ASQ_A= ASQ_COM_A+ASQ_MOTG_A+ASQ_MOTF_A+ASQ_RESP_A+ASQ_SOCI_A if cuest==54
replace avg_A= ASQ_A/5 if cuest==54
replace ASQ_B =ASQ_COM_B+ASQ_MOTG_B+ASQ_MOTF_B+ASQ_RESP_B+ASQ_SOCI_B if cuest==54
replace avg_B = ASQ_B/4 if cuest==54
replace ASQ_C =ASQ_COM_C+ASQ_MOTG_C+ASQ_MOTF_C+ASQ_RESP_C+ASQ_SOCI_C if cuest==54
replace avg_C = ASQ_C/21 if cuest==54

***60 MESES***
replace ASQ_COM_A = 0 if cuest ==60
replace ASQ_COM_B = SCOM_02 if cuest==60
replace ASQ_COM_C = SCOM_01+SCOM_03+SCOM_04+SCOM_05+SCOM_06 if cuest==60

replace ASQ_MOTG_A = 0 if cuest ==60
replace ASQ_MOTG_B = 0 if cuest==60
replace ASQ_MOTG_C = SMOTG_01+SMOTG_02+SMOTG_03+SMOTG_04+SMOTG_05+SMOTG_06 if cuest==60

replace ASQ_MOTF_A = 0 if cuest ==60
replace ASQ_MOTF_B = 0 if cuest==60
replace ASQ_MOTF_C = SMOTF_01+SMOTF_02+SMOTF_03+SMOTF_04+SMOTF_05+SMOTF_06 if cuest==60

replace ASQ_RESP_A = 0 if cuest ==60
replace ASQ_RESP_B = 0 if cuest==60
replace ASQ_RESP_C = SRESP_01+SRESP_02+SRESP_03+SRESP_04+SRESP_05+SRESP_06 if cuest==60

replace ASQ_SOCI_A = SSOCI_01+SSOCI_02+SSOCI_04+SSOCI_05+SSOCI_06 if cuest==60
replace ASQ_SOCI_B = 0 if cuest==60
replace ASQ_SOCI_C = SSOCI_03 if cuest==60

replace ASQ_A= ASQ_COM_A+ASQ_MOTG_A+ASQ_MOTF_A+ASQ_RESP_A+ASQ_SOCI_A if cuest==60
replace avg_A= ASQ_A/5 if cuest==60
replace ASQ_B =ASQ_COM_B+ASQ_MOTG_B+ASQ_MOTF_B+ASQ_RESP_B+ASQ_SOCI_B if cuest==60
replace avg_B = ASQ_B/1 if cuest==60
replace ASQ_C =ASQ_COM_C+ASQ_MOTG_C+ASQ_MOTF_C+ASQ_RESP_C+ASQ_SOCI_C if cuest==60
replace avg_C = ASQ_C/24 if cuest==60
}
*--------------------------------------------------*
*----Summarizing the average score of each mode----*
*--------------------------------------------------*
***** Table A13: Child Development Statistics of different ASQ implementation modes *****

estpost sum avg_A avg_B avg_C if ChildID==1 & wave == 1
esttab using "Tables/Table A13. ASQ by implementation modes.xls", cells( mean sd min max count) replace title("Wave 1")

estpost sum avg_A avg_B avg_C if ChildID==1 & wave == 2
esttab using "Tables/Table A13. ASQ by implementation modes.xls", cells( mean sd min max count) append title("Wave 2")

estpost sum avg_A avg_B avg_C if ChildID==1 & wave == 3
esttab using "Tables/Table A13. ASQ by implementation modes.xls", cells( mean sd min max count) append title("Wave 3")

*---------------------------*
*----Regression analysis----*
*---------------------------*
*----Generating and standardizing variables of two implementation categories: AB-reported & judged;
{
//C-Observed----*
**2 meses**
gen pcom_AB = SCOM_01 + SCOM_02 +SCOM_03 +SCOM_04 +SCOM_05 +SCOM_06 if cuest==2
su pcom_AB if cuest==2
gen pcom_AB_std = (pcom_AB-r(mean))/r(sd) if cuest==2 

gen pmotg_AB= SMOTG_01+SMOTG_02+SMOTG_03+SMOTG_04+SMOTG_05 if cuest==2
su pmotg_AB if cuest==2
gen pmotg_AB_std = (pmotg_AB-r(mean))/r(sd) if cuest==2 
gen pmotg_C = SMOTG_06 if cuest==2 
su pmotg_C if cuest==2
gen pmotg_C_std = (pmotg_C-r(mean))/r(sd) if cuest==2 

gen pmotf_AB= SMOTF_01+SMOTF_04+SMOTF_05+SMOTF_06 if cuest==2
su pmotf_AB if cuest==2
gen pmotf_AB_std = (pmotf_AB-r(mean))/r(sd) if cuest==2 
gen pmotf_C = SMOTF_02+SMOTF_03 if cuest==2 
su pmotf_C if cuest==2
gen pmotf_C_std = (pmotf_C-r(mean))/r(sd) if cuest==2 

gen presp_AB= SRESP_02 if cuest==2
su presp_AB if cuest==2
gen presp_AB_std = (presp_AB-r(mean))/r(sd) if cuest==2 
gen presp_C = SRESP_01+SRESP_03+SRESP_04+SRESP_05+SRESP_06 if cuest==2 
su presp_C if cuest==2
gen presp_C_std = (presp_C-r(mean))/r(sd) if cuest==2 

gen psoci_AB= SSOCI_02+SSOCI_01+SSOCI_03+SSOCI_04+SSOCI_05+SSOCI_06 if cuest==2
su psoci_AB if cuest==2
gen psoci_AB_std = (psoci_AB-r(mean))/r(sd) if cuest==2 

**4 meses**
replace pcom_AB = SCOM_01 + SCOM_02 +SCOM_03 +SCOM_04 +SCOM_05 +SCOM_06 if cuest==4
su pcom_AB if cuest==4
replace pcom_AB_std = (pcom_AB-r(mean))/r(sd) if cuest==4 

replace pmotg_AB= SMOTG_01+SMOTG_05+SMOTG_06 if cuest==4
su pmotg_AB if cuest==4
replace pmotg_AB_std = (pmotg_AB-r(mean))/r(sd) if cuest==4
replace pmotg_C = SMOTG_02+SMOTG_03+SMOTG_04 if cuest==4
su pmotg_C if cuest==4
replace pmotg_C_std = (pmotg_C-r(mean))/r(sd) if cuest==4 

replace pmotf_AB= SMOTF_01+SMOTF_03+SMOTF_04+SMOTF_06 if cuest==4
su pmotf_AB if cuest==4
replace pmotf_AB_std = (pmotf_AB-r(mean))/r(sd) if cuest==4
replace pmotf_C = SMOTF_02+SMOTF_05 if cuest==4
su pmotf_C if cuest==4
replace pmotf_C_std = (pmotf_C-r(mean))/r(sd) if cuest==4

replace presp_AB= SRESP_04+SRESP_05 if cuest==4
su presp_AB if cuest==4 
replace presp_AB_std = (presp_AB-r(mean))/r(sd) if cuest==4
replace presp_C = SRESP_01+SRESP_02+SRESP_03+SRESP_06 if cuest==4
su presp_C if cuest==4
replace presp_C_std = (presp_C-r(mean))/r(sd) if cuest==4

replace psoci_AB= SSOCI_02+SSOCI_01+SSOCI_03+SSOCI_04+SSOCI_05+SSOCI_06 if cuest==4
su psoci_AB if cuest==4
replace psoci_AB_std = (psoci_AB-r(mean))/r(sd) if cuest==4 

**6 meses**
replace pcom_AB = SCOM_01 + SCOM_02 +SCOM_03 +SCOM_04 +SCOM_05 +SCOM_06 if cuest==6
su pcom_AB if cuest==6
replace pcom_AB_std = (pcom_AB-r(mean))/r(sd) if cuest==6 

replace pmotg_AB= SMOTG_01+SMOTG_02+SMOTG_03+SMOTG_05+SMOTG_06 if cuest==6
su pmotg_AB if cuest==6
replace pmotg_AB_std = (pmotg_AB-r(mean))/r(sd) if cuest==6
replace pmotg_C = SMOTG_04 if cuest==6
su pmotg_C if cuest==6
replace pmotg_C_std = (pmotg_C-r(mean))/r(sd) if cuest==6

replace pmotf_AB= SMOTF_01+SMOTF_02 if cuest==6
su pmotf_AB if cuest==6
replace pmotf_AB_std = (pmotf_AB-r(mean))/r(sd) if cuest==6
replace pmotf_C = SMOTF_03+SMOTF_04+SMOTF_05+SMOTF_06 if cuest==6
su pmotf_C if cuest==6
replace pmotf_C_std = (pmotf_C-r(mean))/r(sd) if cuest==6

replace presp_AB= SRESP_02+SRESP_03+SRESP_04+SRESP_05+SRESP_06 if cuest==6
su presp_AB if cuest==6
replace presp_AB_std = (presp_AB-r(mean))/r(sd) if cuest==6
replace presp_C = SRESP_01 if cuest==6
su presp_C if cuest==6
replace presp_C_std = (presp_C-r(mean))/r(sd) if cuest==6

replace psoci_AB= SSOCI_02+SSOCI_01+SSOCI_03+SSOCI_04+SSOCI_05+SSOCI_06 if cuest==6
su psoci_AB if cuest==6
replace psoci_AB_std = (psoci_AB-r(mean))/r(sd) if cuest==6


**8 meses**
replace pcom_AB = SCOM_01 + SCOM_02 +SCOM_03 +SCOM_04 +SCOM_05 +SCOM_06 if cuest==8
su pcom_AB if cuest==8
replace pcom_AB_std = (pcom_AB-r(mean))/r(sd) if cuest==8

replace pmotg_AB= SMOTG_02+SMOTG_03+SMOTG_04+SMOTG_05+SMOTG_06 if cuest==8
su pmotg_AB if cuest==8
replace pmotg_AB_std = (pmotg_AB-r(mean))/r(sd) if cuest==8
replace pmotg_C = SMOTG_01 if cuest==8
su pmotg_C if cuest==8
replace pmotg_C_std = (pmotg_C-r(mean))/r(sd) if cuest==8

replace pmotf_C = SMOTF_01+SMOTF_02+SMOTF_03+SMOTF_04+SMOTF_05+SMOTF_06 if cuest==8
su pmotf_C if cuest==8
replace pmotf_C_std = (pmotf_C-r(mean))/r(sd) if cuest==8

replace presp_C = SRESP_01 + SRESP_02+SRESP_03+SRESP_04+SRESP_05+SRESP_06 if cuest==8
su presp_C if cuest==8
replace presp_C_std = (presp_C-r(mean))/r(sd) if cuest==8

replace psoci_AB= SSOCI_02+SSOCI_01+SSOCI_04+SSOCI_05+SSOCI_06 if cuest==8
su psoci_AB if cuest==8
replace psoci_AB_std = (psoci_AB-r(mean))/r(sd) if cuest==8
gen psoci_C = SSOCI_03 if cuest==8
su psoci_C if cuest==8
gen psoci_C_std = (psoci_C-r(mean))/r(sd) if cuest==8

**10 meses**
replace pcom_AB = SCOM_01 + SCOM_02 +SCOM_03 +SCOM_04 +SCOM_05 +SCOM_06 if cuest==10
su pcom_AB if cuest==10
replace pcom_AB_std = (pcom_AB-r(mean))/r(sd) if cuest==10

replace pmotg_AB= SMOTG_03+SMOTG_04+SMOTG_05+SMOTG_06 if cuest==10
su pmotg_AB if cuest==10
replace pmotg_AB_std = (pmotg_AB-r(mean))/r(sd) if cuest==10
replace pmotg_C = SMOTG_01+SMOTG_02 if cuest==10
su pmotg_C if cuest==10
replace pmotg_C_std = (pmotg_C-r(mean))/r(sd) if cuest==10

replace pmotf_C = SMOTF_01+SMOTF_02+SMOTF_03+SMOTF_04+SMOTF_05+SMOTF_06 if cuest==10
su pmotf_C if cuest==10
replace pmotf_C_std = (pmotf_C-r(mean))/r(sd) if cuest==10

replace presp_C = SRESP_01 + SRESP_02+SRESP_03+SRESP_04+SRESP_05+SRESP_06 if cuest==10
su presp_C if cuest==10
replace presp_C_std = (presp_C-r(mean))/r(sd) if cuest==10

replace psoci_AB= SSOCI_03+SSOCI_02+SSOCI_01+SSOCI_04+SSOCI_05+SSOCI_06 if cuest==10
su psoci_AB if cuest==10
replace psoci_AB_std = (psoci_AB-r(mean))/r(sd) if cuest==10


***12 meses**
replace pcom_AB = SCOM_01 + SCOM_02 +SCOM_03 +SCOM_04 if cuest==12
su pcom_AB if cuest==12
replace pcom_AB_std = (pcom_AB-r(mean))/r(sd) if cuest==12
gen pcom_C = SCOM_05 +SCOM_06 if cuest==12
su pcom_C if cuest==12
gen pcom_C_std = (pcom_C-r(mean))/r(sd) if cuest==12

replace pmotg_AB= SMOTG_01+SMOTG_02+SMOTG_03+SMOTG_06 if cuest==12
su pmotg_AB if cuest==12
replace pmotg_AB_std = (pmotg_AB-r(mean))/r(sd) if cuest==12
replace pmotg_C = SMOTG_04+SMOTG_05 if cuest==12
su pmotg_C if cuest==12
replace pmotg_C_std = (pmotg_C-r(mean))/r(sd) if cuest==12

replace pmotf_C = SMOTF_01+SMOTF_02+SMOTF_03+SMOTF_04+SMOTF_05+SMOTF_06 if cuest==12
su pmotf_C if cuest==12
replace pmotf_C_std = (pmotf_C-r(mean))/r(sd) if cuest==12

replace presp_C = SRESP_01 + SRESP_02+SRESP_03+SRESP_04+SRESP_05+SRESP_06 if cuest==12
su presp_C if cuest==12
replace presp_C_std = (presp_C-r(mean))/r(sd) if cuest==12

replace psoci_AB= SSOCI_03+SSOCI_02+SSOCI_01+SSOCI_04+SSOCI_05+SSOCI_06 if cuest==12
su psoci_AB if cuest==12
replace psoci_AB_std = (psoci_AB-r(mean))/r(sd) if cuest==12


***14 meses**
replace pcom_AB = SCOM_01 + SCOM_02 +SCOM_03 +SCOM_05 if cuest==14
su pcom_AB if cuest==14
replace pcom_AB_std = (pcom_AB-r(mean))/r(sd) if cuest==14
replace pcom_C = SCOM_04 +SCOM_06 if cuest==14
su pcom_C if cuest==14
replace pcom_C_std = (pcom_C-r(mean))/r(sd) if cuest==14

replace pmotg_AB= SMOTG_03+SMOTG_04+SMOTG_05+SMOTG_06 if cuest==14
su pmotg_AB if cuest==14
replace pmotg_AB_std = (pmotg_AB-r(mean))/r(sd) if cuest==14
replace pmotg_C = SMOTG_01+SMOTG_02 if cuest==14
su pmotg_C if cuest==14
replace pmotg_C_std = (pmotg_C-r(mean))/r(sd) if cuest==14

replace pmotf_AB= SMOTF_03 if cuest==14
su pmotf_AB if cuest==14
replace pmotf_AB_std = (pmotf_AB-r(mean))/r(sd) if cuest==14
replace pmotf_C = SMOTF_01+SMOTF_02+SMOTF_04+SMOTF_05+SMOTF_06 if cuest==14
su pmotf_C if cuest==14
replace pmotf_C_std = (pmotf_C-r(mean))/r(sd) if cuest==14

replace presp_C = SRESP_01 + SRESP_02+SRESP_03+SRESP_04+SRESP_05+SRESP_06 if cuest==14
su presp_C if cuest==14
replace presp_C_std = (presp_C-r(mean))/r(sd) if cuest==14

replace psoci_AB= SSOCI_03+SSOCI_02+SSOCI_01+SSOCI_04+SSOCI_05+SSOCI_06 if cuest==14
su psoci_AB if cuest==14
replace psoci_AB_std = (psoci_AB-r(mean))/r(sd) if cuest==14

***16 meses**
replace pcom_AB = SCOM_03 if cuest==16
su pcom_AB if cuest==16
replace pcom_AB_std = (pcom_AB-r(mean))/r(sd) if cuest==16
replace pcom_C = SCOM_01 +SCOM_02 + SCOM_04 + SCOM_05 +SCOM_06 if cuest==16
su pcom_C if cuest==16
replace pcom_C_std = (pcom_C-r(mean))/r(sd) if cuest==16

replace pmotg_AB= SMOTG_02 +SMOTG_03+SMOTG_04+SMOTG_05+SMOTG_06 if cuest==16
su pmotg_AB if cuest==16
replace pmotg_AB_std = (pmotg_AB-r(mean))/r(sd) if cuest==16
replace pmotg_C = SMOTG_01 if cuest==16
su pmotg_C if cuest==16
replace pmotg_C_std = (pmotg_C-r(mean))/r(sd) if cuest==16

replace pmotf_C = SMOTF_01+SMOTF_02+SMOTF_03+SMOTF_05+SMOTF_06+SMOTF_04 if cuest==16
su pmotf_C if cuest==16
replace pmotf_C_std = (pmotf_C-r(mean))/r(sd) if cuest==16

replace presp_C = SRESP_01 + SRESP_02+SRESP_03+SRESP_04+SRESP_05+SRESP_06 if cuest==16
su presp_C if cuest==16
replace presp_C_std = (presp_C-r(mean))/r(sd) if cuest==16

replace psoci_AB= SSOCI_03+SSOCI_02+SSOCI_01+SSOCI_04+SSOCI_05+SSOCI_06 if cuest==16
su psoci_AB if cuest==16
replace psoci_AB_std = (psoci_AB-r(mean))/r(sd) if cuest==16

***18 meses**
replace pcom_AB = SCOM_01 +SCOM_02 + SCOM_03 + SCOM_04 +SCOM_06 if cuest==18
su pcom_AB if cuest==18
replace pcom_AB_std = (pcom_AB-r(mean))/r(sd) if cuest==18
replace pcom_C = SCOM_05  if cuest==18
su pcom_C if cuest==18
replace pcom_C_std = (pcom_C-r(mean))/r(sd) if cuest==18

replace pmotg_AB= SMOTG_02 +SMOTG_03+SMOTG_04+SMOTG_05 if cuest==18
su pmotg_AB if cuest==18
replace pmotg_AB_std = (pmotg_AB-r(mean))/r(sd) if cuest==18
replace pmotg_C = SMOTG_01+SMOTG_06 if cuest==18
su pmotg_C if cuest==18
replace pmotg_C_std = (pmotg_C-r(mean))/r(sd) if cuest==18

replace pmotf_C = SMOTF_01+SMOTF_02+SMOTF_03+SMOTF_05+SMOTF_06+SMOTF_04 if cuest==18
su pmotf_C if cuest==18
replace pmotf_C_std = (pmotf_C-r(mean))/r(sd) if cuest==18

replace presp_C = SRESP_01 + SRESP_02+SRESP_03+SRESP_04+SRESP_05+SRESP_06 if cuest==18
su presp_C if cuest==18
replace presp_C_std = (presp_C-r(mean))/r(sd) if cuest==18

replace psoci_AB= SSOCI_03+SSOCI_02+SSOCI_01+SSOCI_04+SSOCI_05+SSOCI_06 if cuest==18
su psoci_AB if cuest==18
replace psoci_AB_std = (psoci_AB-r(mean))/r(sd) if cuest==18

***20 meses**
replace pcom_AB = SCOM_01 +SCOM_02 +SCOM_06 if cuest==20
su pcom_AB if cuest==20
replace pcom_AB_std = (pcom_AB-r(mean))/r(sd) if cuest==20
replace pcom_C = SCOM_05 + SCOM_03 + SCOM_04   if cuest==20
su pcom_C if cuest==20
replace pcom_C_std = (pcom_C-r(mean))/r(sd) if cuest==20

replace pmotg_AB= SMOTG_01 +SMOTG_02+SMOTG_03+SMOTG_05 if cuest==20
su pmotg_AB if cuest==20
replace pmotg_AB_std = (pmotg_AB-r(mean))/r(sd) if cuest==20
replace pmotg_C = SMOTG_04+SMOTG_06 if cuest==20
su pmotg_C if cuest==20
replace pmotg_C_std = (pmotg_C-r(mean))/r(sd) if cuest==20

replace pmotf_AB= SMOTF_01+SMOTF_02+SMOTF_05+SMOTF_06 if cuest==20
su pmotf_AB if cuest==20
replace pmotf_AB_std = (pmotf_AB-r(mean))/r(sd) if cuest==20
replace pmotf_C = SMOTF_03+SMOTF_04 if cuest==20
su pmotf_C if cuest==20
replace pmotf_C_std = (pmotf_C-r(mean))/r(sd) if cuest==20

replace presp_AB= SRESP_04+SRESP_06 if cuest==20
su presp_AB if cuest==20
replace presp_AB_std = (presp_AB-r(mean))/r(sd) if cuest==20
replace presp_C = SRESP_01 + SRESP_02+SRESP_03+SRESP_05 if cuest==20
su presp_C if cuest==20
replace presp_C_std = (presp_C-r(mean))/r(sd) if cuest==20

replace psoci_AB= SSOCI_03+SSOCI_02+SSOCI_01+SSOCI_04+SSOCI_05+SSOCI_06 if cuest==20
su psoci_AB if cuest==20
replace psoci_AB_std = (psoci_AB-r(mean))/r(sd) if cuest==20

***22 meses**
replace pcom_AB = SCOM_04 +SCOM_05 +SCOM_06 if cuest==22
su pcom_AB if cuest==22
replace pcom_AB_std = (pcom_AB-r(mean))/r(sd) if cuest==22
replace pcom_C = SCOM_01 + SCOM_02 + SCOM_03   if cuest==22
su pcom_C if cuest==22
replace pcom_C_std = (pcom_C-r(mean))/r(sd) if cuest==22

replace pmotg_AB= SMOTG_02 +SMOTG_03+SMOTG_04 if cuest==22
su pmotg_AB if cuest==22
replace pmotg_AB_std = (pmotg_AB-r(mean))/r(sd) if cuest==22
replace pmotg_C = SMOTG_01+SMOTG_05+SMOTG_06 if cuest==22
su pmotg_C if cuest==22
replace pmotg_C_std = (pmotg_C-r(mean))/r(sd) if cuest==22

replace pmotf_AB= SMOTF_01+SMOTF_05 if cuest==22
su pmotf_AB if cuest==22
replace pmotf_AB_std = (pmotf_AB-r(mean))/r(sd) if cuest==22
replace pmotf_C = SMOTF_02+SMOTF_03+SMOTF_04+SMOTF_06 if cuest==22
su pmotf_C if cuest==22
replace pmotf_C_std = (pmotf_C-r(mean))/r(sd) if cuest==22

replace presp_AB= SRESP_03+SRESP_06 if cuest==22
su presp_AB if cuest==22
replace presp_AB_std = (presp_AB-r(mean))/r(sd) if cuest==22
replace presp_C = SRESP_02 + SRESP_03+SRESP_04+SRESP_05 if cuest==22
su presp_C if cuest==22
replace presp_C_std = (presp_C-r(mean))/r(sd) if cuest==22

replace psoci_AB= SSOCI_01+SSOCI_03+SSOCI_04+SSOCI_05+SSOCI_06 if cuest==22
su psoci_AB if cuest==22
replace psoci_AB_std = (psoci_AB-r(mean))/r(sd) if cuest==22
replace psoci_C = SSOCI_02 if cuest==22
su psoci_C if cuest==22
replace psoci_C_std = (psoci_C-r(mean))/r(sd) if cuest==22

**24 meses**
replace pcom_AB = SCOM_02 +SCOM_05 +SCOM_06 if cuest==24
su pcom_AB if cuest==24
replace pcom_AB_std = (pcom_AB-r(mean))/r(sd) if cuest==24
replace pcom_C = SCOM_01 + SCOM_04 + SCOM_03   if cuest==24
su pcom_C if cuest==24
replace pcom_C_std = (pcom_C-r(mean))/r(sd) if cuest==24

replace pmotg_AB= SMOTG_01 +SMOTG_03+SMOTG_04 if cuest==24
su pmotg_AB if cuest==24
replace pmotg_AB_std = (pmotg_AB-r(mean))/r(sd) if cuest==24
replace pmotg_C = SMOTG_02+SMOTG_05+SMOTG_06 if cuest==24
su pmotg_C if cuest==24
replace pmotg_C_std = (pmotg_C-r(mean))/r(sd) if cuest==24

replace pmotf_AB= SMOTF_01+SMOTF_02+SMOTF_04 if cuest==24
su pmotf_AB if cuest==24
replace pmotf_AB_std = (pmotf_AB-r(mean))/r(sd) if cuest==24
replace pmotf_C = SMOTF_03+SMOTF_05+SMOTF_06 if cuest==24
su pmotf_C if cuest==24
replace pmotf_C_std = (pmotf_C-r(mean))/r(sd) if cuest==24

replace presp_AB= SRESP_03+SRESP_04+SRESP_05 if cuest==24
su presp_AB if cuest==24
replace presp_AB_std = (presp_AB-r(mean))/r(sd) if cuest==24
replace presp_C = SRESP_01+SRESP_02+SRESP_06 if cuest==24
su presp_C if cuest==24
replace presp_C_std = (presp_C-r(mean))/r(sd) if cuest==24

replace psoci_AB= SSOCI_01+SSOCI_02+SSOCI_03+SSOCI_04+SSOCI_05+SSOCI_06 if cuest==24
su psoci_AB if cuest==24
replace psoci_AB_std = (psoci_AB-r(mean))/r(sd) if cuest==24

**27 meses**
replace pcom_AB = SCOM_04 +SCOM_05 if cuest==27
su pcom_AB if cuest==27
replace pcom_AB_std = (pcom_AB-r(mean))/r(sd) if cuest==27
replace pcom_C = SCOM_01 + SCOM_02 + SCOM_03 +SCOM_06  if cuest==27
su pcom_C if cuest==27
replace pcom_C_std = (pcom_C-r(mean))/r(sd) if cuest==27

replace pmotg_AB= SMOTG_01 +SMOTG_02+SMOTG_06 if cuest==27
su pmotg_AB if cuest==27
replace pmotg_AB_std = (pmotg_AB-r(mean))/r(sd) if cuest==27
replace pmotg_C = SMOTG_03+SMOTG_04+SMOTG_05 if cuest==27
su pmotg_C if cuest==27
replace pmotg_C_std = (pmotg_C-r(mean))/r(sd) if cuest==27

replace pmotf_AB= SMOTF_02 if cuest==27
su pmotf_AB if cuest==27
replace pmotf_AB_std = (pmotf_AB-r(mean))/r(sd) if cuest==27
replace pmotf_C = SMOTF_03+SMOTF_05+SMOTF_06+SMOTF_01+SMOTF_04 if cuest==27
su pmotf_C if cuest==27
replace pmotf_C_std = (pmotf_C-r(mean))/r(sd) if cuest==27

replace presp_AB= SRESP_01+SRESP_02+SRESP_04 if cuest==27
su presp_AB if cuest==27
replace presp_AB_std = (presp_AB-r(mean))/r(sd) if cuest==27
replace presp_C = SRESP_03+SRESP_05+SRESP_06 if cuest==27
su presp_C if cuest==27
replace presp_C_std = (presp_C-r(mean))/r(sd) if cuest==27

replace psoci_AB= SSOCI_02+SSOCI_03+SSOCI_04+SSOCI_05+SSOCI_06 if cuest==27
su psoci_AB if cuest==27
replace psoci_AB_std = (psoci_AB-r(mean))/r(sd) if cuest==27
replace psoci_C= SSOCI_01 if cuest==27
su psoci_C if cuest==27
replace psoci_C_std = (psoci_C-r(mean))/r(sd) if cuest==27

**30 meses**
replace pcom_AB = SCOM_04 if cuest==30
su pcom_AB if cuest==30
replace pcom_AB_std = (pcom_AB-r(mean))/r(sd) if cuest==30
replace pcom_C = SCOM_01 + SCOM_02 + SCOM_03 +SCOM_05+SCOM_06  if cuest==30
su pcom_C if cuest==30
replace pcom_C_std = (pcom_C-r(mean))/r(sd) if cuest==30

replace pmotg_AB= SMOTG_01 +SMOTG_02+SMOTG_05 if cuest==30
su pmotg_AB if cuest==30
replace pmotg_AB_std = (pmotg_AB-r(mean))/r(sd) if cuest==30
replace pmotg_C = SMOTG_03+SMOTG_04+SMOTG_06 if cuest==30
su pmotg_C if cuest==30
replace pmotg_C_std = (pmotg_C-r(mean))/r(sd) if cuest==30

replace pmotf_AB= SMOTF_06 if cuest==30
su pmotf_AB if cuest==30
replace pmotf_AB_std = (pmotf_AB-r(mean))/r(sd) if cuest==30
replace pmotf_C = SMOTF_01+SMOTF_02+SMOTF_03+SMOTF_04+SMOTF_05 if cuest==30
su pmotf_C if cuest==30
replace pmotf_C_std = (pmotf_C-r(mean))/r(sd) if cuest==30

replace presp_AB= SRESP_02 if cuest==30
su presp_AB if cuest==30
replace presp_AB_std = (presp_AB-r(mean))/r(sd) if cuest==30
replace presp_C = SRESP_01+SRESP_03+SRESP_04+SRESP_05+SRESP_06 if cuest==30
su presp_C if cuest==30
replace presp_C_std = (presp_C-r(mean))/r(sd) if cuest==30

replace psoci_AB= SSOCI_02+SSOCI_03+SSOCI_04+SSOCI_05 if cuest==30
su psoci_AB if cuest==30
replace psoci_AB_std = (psoci_AB-r(mean))/r(sd) if cuest==30
replace psoci_C= SSOCI_01+SSOCI_06 if cuest==30
su psoci_C if cuest==30
replace psoci_C_std = (psoci_C-r(mean))/r(sd) if cuest==30

**33 meses**
replace pcom_AB = SCOM_02 if cuest==33
su pcom_AB if cuest==33
replace pcom_AB_std = (pcom_AB-r(mean))/r(sd) if cuest==33
replace pcom_C = SCOM_01 + SCOM_04 + SCOM_03 +SCOM_05+SCOM_06  if cuest==33
su pcom_C if cuest==33
replace pcom_C_std = (pcom_C-r(mean))/r(sd) if cuest==33

replace pmotg_AB= SMOTG_01 +SMOTG_04 if cuest==33
su pmotg_AB if cuest==33
replace pmotg_AB_std = (pmotg_AB-r(mean))/r(sd) if cuest==33
replace pmotg_C = SMOTG_02+SMOTG_03+SMOTG_05+SMOTG_06 if cuest==33
su pmotg_C if cuest==33
replace pmotg_C_std = (pmotg_C-r(mean))/r(sd) if cuest==33

replace pmotf_AB= SMOTF_05 if cuest==33
su pmotf_AB if cuest==33
replace pmotf_AB_std = (pmotf_AB-r(mean))/r(sd) if cuest==33
replace pmotf_C = SMOTF_01+SMOTF_02+SMOTF_03+SMOTF_04+SMOTF_06 if cuest==33
su pmotf_C if cuest==33
replace pmotf_C_std = (pmotf_C-r(mean))/r(sd) if cuest==33

replace presp_AB= SRESP_03 if cuest==33
su presp_AB if cuest==33
replace presp_AB_std = (presp_AB-r(mean))/r(sd) if cuest==33
replace presp_C = SRESP_01+SRESP_02+SRESP_04+SRESP_05+SRESP_06 if cuest==33
su presp_C if cuest==33
replace presp_C_std = (presp_C-r(mean))/r(sd) if cuest==33

replace psoci_AB= SSOCI_01+SSOCI_02+SSOCI_03+SSOCI_04 if cuest==33
su psoci_AB if cuest==33
replace psoci_AB_std = (psoci_AB-r(mean))/r(sd) if cuest==33
replace psoci_C= SSOCI_05+SSOCI_06 if cuest==33
su psoci_C if cuest==33
replace psoci_C_std = (psoci_C-r(mean))/r(sd) if cuest==33

**36 meses**
replace pcom_AB = SCOM_02 if cuest==36
su pcom_AB if cuest==36
replace pcom_AB_std = (pcom_AB-r(mean))/r(sd) if cuest==36
replace pcom_C = SCOM_01 + SCOM_04 + SCOM_03 +SCOM_05+SCOM_06  if cuest==36
su pcom_C if cuest==36
replace pcom_C_std = (pcom_C-r(mean))/r(sd) if cuest==36

replace pmotg_AB= SMOTG_03 if cuest==36
su pmotg_AB if cuest==36
replace pmotg_AB_std = (pmotg_AB-r(mean))/r(sd) if cuest==36
replace pmotg_C = SMOTG_01+SMOTG_02+SMOTG_04+SMOTG_05+SMOTG_06 if cuest==36
su pmotg_C if cuest==36
replace pmotg_C_std = (pmotg_C-r(mean))/r(sd) if cuest==36

replace pmotf_C = SMOTF_01+SMOTF_02+SMOTF_03+SMOTF_04+SMOTF_05+SMOTF_06 if cuest==36
su pmotf_C if cuest==36
replace pmotf_C_std = (pmotf_C-r(mean))/r(sd) if cuest==36

replace presp_AB= SRESP_02 if cuest==36
su presp_AB if cuest==36
replace presp_AB_std = (presp_AB-r(mean))/r(sd) if cuest==36
replace presp_C = SRESP_01+SRESP_03+SRESP_04+SRESP_05+SRESP_06 if cuest==36
su presp_C if cuest==36
replace presp_C_std = (presp_C-r(mean))/r(sd) if cuest==36

replace psoci_AB= SSOCI_01+SSOCI_02+SSOCI_04+SSOCI_06 if cuest==36
su psoci_AB if cuest==36
replace psoci_AB_std = (psoci_AB-r(mean))/r(sd) if cuest==36
replace psoci_C= SSOCI_03+SSOCI_05 if cuest==36
su psoci_C if cuest==36
replace psoci_C_std = (psoci_C-r(mean))/r(sd) if cuest==36

**42 meses**
replace pcom_AB = SCOM_06 if cuest==42
su pcom_AB if cuest==42
replace pcom_AB_std = (pcom_AB-r(mean))/r(sd) if cuest==42
replace pcom_C = SCOM_01 + SCOM_02 + SCOM_03 +SCOM_04+SCOM_05  if cuest==42
su pcom_C if cuest==42
replace pcom_C_std = (pcom_C-r(mean))/r(sd) if cuest==42

replace pmotg_AB= SMOTG_01 +SMOTG_06 if cuest==42
su pmotg_AB if cuest==42
replace pmotg_AB_std = (pmotg_AB-r(mean))/r(sd) if cuest==42
replace pmotg_C = SMOTG_02+SMOTG_03+SMOTG_04+SMOTG_05 if cuest==42
su pmotg_C if cuest==42
replace pmotg_C_std = (pmotg_C-r(mean))/r(sd) if cuest==42

replace pmotf_C = SMOTF_01+SMOTF_02+SMOTF_03+SMOTF_04+SMOTF_05+SMOTF_06 if cuest==42
su pmotf_C if cuest==42
replace pmotf_C_std = (pmotf_C-r(mean))/r(sd) if cuest==42

replace presp_AB = SRESP_06 if cuest==42
su presp_C if cuest==42
replace presp_C_std = (presp_C-r(mean))/r(sd) if cuest==42
replace presp_C = SRESP_01+SRESP_02+SRESP_04+SRESP_05+SRESP_03 if cuest==42
su presp_C if cuest==42
replace presp_C_std = (presp_C-r(mean))/r(sd) if cuest==42

replace psoci_AB= SSOCI_02+SSOCI_04+SSOCI_05+SSOCI_06  if cuest==42
su psoci_AB if cuest==42
replace psoci_AB_std = (psoci_AB-r(mean))/r(sd) if cuest==42
replace psoci_C= SSOCI_01+SSOCI_03 if cuest==42
su psoci_C if cuest==42
replace psoci_C_std = (psoci_C-r(mean))/r(sd) if cuest==42

**48 meses**
replace pcom_AB = SCOM_06 if cuest==48
su pcom_AB if cuest==48
replace pcom_AB_std = (pcom_AB-r(mean))/r(sd) if cuest==48
replace pcom_C = SCOM_01 + SCOM_02 + SCOM_03 +SCOM_04+SCOM_05  if cuest==48
su pcom_C if cuest==48
replace pcom_C_std = (pcom_C-r(mean))/r(sd) if cuest==48

replace pmotg_AB= SMOTG_01 +SMOTG_03+SMOTG_04 +SMOTG_06+SMOTG_05 if cuest==48
su pmotg_AB if cuest==48
replace pmotg_AB_std = (pmotg_AB-r(mean))/r(sd) if cuest==48
replace pmotg_C = SMOTG_02  if cuest==48
su pmotg_C if cuest==48
replace pmotg_C_std = (pmotg_C-r(mean))/r(sd) if cuest==48

replace pmotf_AB = SMOTF_04 if cuest==48
su pmotf_C if cuest==48
replace pmotf_C_std = (pmotf_C-r(mean))/r(sd) if cuest==48
replace pmotf_C = SMOTF_01+SMOTF_02+SMOTF_03+SMOTF_05+SMOTF_06 if cuest==48
su pmotf_C if cuest==48
replace pmotf_C_std = (pmotf_C-r(mean))/r(sd) if cuest==48

replace presp_AB = SRESP_05 if cuest==48
su presp_C if cuest==48
replace presp_C_std = (presp_C-r(mean))/r(sd) if cuest==48
replace presp_C = SRESP_01+SRESP_02+SRESP_04+SRESP_06+SRESP_03 if cuest==48
su presp_C if cuest==48
replace presp_C_std = (presp_C-r(mean))/r(sd) if cuest==48

replace psoci_AB= SSOCI_01+SSOCI_03+SSOCI_05+SSOCI_06  if cuest==48
su psoci_AB if cuest==48
replace psoci_AB_std = (psoci_AB-r(mean))/r(sd) if cuest==48
replace psoci_C= SSOCI_02+SSOCI_04 if cuest==48
su psoci_C if cuest==48
replace psoci_C_std = (psoci_C-r(mean))/r(sd) if cuest==48

**54 meses**
replace pcom_AB = SCOM_02+SCOM_03+SCOM_05 if cuest==54
su pcom_AB if cuest==54
replace pcom_AB_std = (pcom_AB-r(mean))/r(sd) if cuest==54
replace pcom_C = SCOM_01+SCOM_04+SCOM_06 if cuest==54
su pcom_C if cuest==54
replace pcom_C_std = (pcom_C-r(mean))/r(sd) if cuest==54

replace pmotg_AB= SMOTG_01 +SMOTG_03+SMOTG_04 +SMOTG_06+SMOTG_05 if cuest==54
su pmotg_AB if cuest==54
replace pmotg_AB_std = (pmotg_AB-r(mean))/r(sd) if cuest==54
replace pmotg_C = SMOTG_02  if cuest==54
su pmotg_C if cuest==54
replace pmotg_C_std = (pmotg_C-r(mean))/r(sd) if cuest==54

replace pmotf_C = SMOTF_01+SMOTF_02+SMOTF_03+SMOTF_05+SMOTF_06+SMOTF_04 if cuest==54
su pmotf_C if cuest==54
replace pmotf_C_std = (pmotf_C-r(mean))/r(sd) if cuest==54

replace presp_AB = SRESP_02 if cuest==54
su presp_C if cuest==54
replace presp_C_std = (presp_C-r(mean))/r(sd) if cuest==54
replace presp_C = SRESP_01+SRESP_05+SRESP_04+SRESP_06+SRESP_03 if cuest==54
su presp_C if cuest==54
replace presp_C_std = (presp_C-r(mean))/r(sd) if cuest==54

replace psoci_AB= SSOCI_01+SSOCI_03+SSOCI_04+SSOCI_06 if cuest==54
su psoci_AB if cuest==54
replace psoci_AB_std = (psoci_AB-r(mean))/r(sd) if cuest==54
replace psoci_C= SSOCI_02+SSOCI_05 if cuest==54
su psoci_C if cuest==54
replace psoci_C_std = (psoci_C-r(mean))/r(sd) if cuest==54

**60 meses**
replace pcom_AB = SCOM_02 if cuest==60
su pcom_AB if cuest==60
replace pcom_AB_std = (pcom_AB-r(mean))/r(sd) if cuest==60
replace pcom_C = SCOM_01+SCOM_03+SCOM_04+SCOM_05+SCOM_06 if cuest==60
su pcom_C if cuest==60
replace pcom_C_std = (pcom_C-r(mean))/r(sd) if cuest==60

replace pmotg_C = SMOTG_01+SMOTG_02+SMOTG_03+SMOTG_04+SMOTG_05+SMOTG_06 if cuest==60
su pmotg_C if cuest==60
replace pmotg_C_std = (pmotg_C-r(mean))/r(sd) if cuest==60

replace pmotf_C = SMOTF_01+SMOTF_02+SMOTF_03+SMOTF_05+SMOTF_06+SMOTF_04 if cuest==60
su pmotf_C if cuest==60
replace pmotf_C_std = (pmotf_C-r(mean))/r(sd) if cuest==60

replace presp_C = SRESP_01+SRESP_05+SRESP_04+SRESP_06+SRESP_03+SRESP_02 if cuest==60
su presp_C if cuest==60
replace presp_C_std = (presp_C-r(mean))/r(sd) if cuest==60

replace psoci_AB= SSOCI_01+SSOCI_02+SSOCI_04+SSOCI_05+SSOCI_06 if cuest==60
su psoci_AB if cuest==60
replace psoci_AB_std = (psoci_AB-r(mean))/r(sd) if cuest==60
replace psoci_C= SSOCI_03 if cuest==60
su psoci_C if cuest==60
replace psoci_C_std = (psoci_C-r(mean))/r(sd) if cuest==60
}
*----Generating the index:sum----*
gen ptotal_AB = pcom_AB_std + pmotg_AB_std + pmotf_AB_std + presp_AB_std + psoci_AB_std 
gen ptotal_C = pcom_C_std + pmotg_C_std + pmotf_C_std + presp_C_std + psoci_C_std 
*standardize the indices
sum ptotal_AB if ChildID==1  //sum mean and standard error
gen ptotal_AB_std = (ptotal_AB-r(mean))/r(sd)  //standardizing the scores 
sum ptotal_AB_std if ChildID==1  //testing the results 
*standardize the indices
sum ptotal_C if ChildID==1  //sum mean and standard error
gen ptotal_C_std = (ptotal_C-r(mean))/r(sd)  //standardizing the scores 
sum ptotal_C_std if ChildID==1  //testing the results 

*------------------*
*----Regression----*
*------------------*
***** Table A14: Regression Analysis of ASQ Implementation Modes *****
foreach var of varlist ptotal_AB_std ptotal_C_std pcom_AB_std pcom_C_std pmotg_AB_std pmotg_C_std pmotf_AB_std pmotf_C_std presp_AB_std presp_C_std psoci_AB_std psoci_C_std {
	d `var'
	xtreg `var' trt_2 trt_3 wave2 wave3 if ChildID==1, fe i (community) vce (cluster community)
	outreg2 using "Tables/Table A14. Regression Analysis of ASQ Implementation Modes.xls", append dec(2)
}

*-----------------------------------------------*
*                                               *
*    Robusteness Check II:Order Effect          * 
*                                               *
*-----------------------------------------------*
//Note: This part is to check if the implementation order of ASQ and Caregiver 
//questionnaires would be a factor that biases the impact. 

*----Generating ASQ-first dummy----*
gen entvdiapresent = 1 if fecha_ASQ~=. & fecha_CU~=. //Interview date available 
*-----Comparing the day order of two interviews----*
gen ninoprimero_d =1 if entvdiapresent==1 & fecha_ASQ < fecha_CU //ASQ first 
replace ninoprimero_d = 0 if entvdiapresent==1 & fecha_ASQ == fecha_CU //Same day 
replace ninoprimero_d = -1 if entvdiapresent==1 & fecha_ASQ > fecha_CU //Caregiver first
*-----Comparing the hour order of two interviews that took place on the same day----*
gen entvhorapresent = 1 if hini_ASQ~=. & hini_CU~=. & ninoprimero_d==0 //Hour available 
gen ninoprimero_h =1 if ninoprimero_d==0 & hini_ASQ < hini_CU & entvhorapresent==1 //ASQ first
replace ninoprimero_h=0 if ninoprimero_d==0 & hini_ASQ> hini_CU & entvhorapresent==1 //Caregiver first
*----Summarizing the order statistics----*
tab ninoprimero_d 
tab ninoprimero_h
*----Generating the dummy of order for interviews that took place on the same day----*
//Note: We only checked this sub-sample as more 95% of ASQ and Caregiver interviews were
//taken on the same day
gen ASQprimero=1 if ninoprimero_d==0 & ninoprimero_h==1
replace ASQprimero=0 if ASQprimero==.
*----------------------------*
*-----Regression analysis----*
*----------------------------*
***** Table A15. Regression Analysis of ASQ and Caregiver Questionnaire Implementation Order  *****

	
*----Parenting Practices Index---*	
reg opi_pca_std ASQprimero if CuidID==1 & cuid_present_b==1
	outreg2 using "Tables/Table A15. Regression Analysis of ASQ and Caregiver Questionnaire Implementation Order.xls", replace dec(2)
reg opi2_pca_std ASQprimero if CuidID==1 & cuid_present_b==1
	outreg2 using "Tables/Table A15. Regression Analysis of ASQ and Caregiver Questionnaire Implementation Order.xls", append dec(2)

*----Child Development Impact----*
foreach var of varlist pcom_std pmotg_std pmotf_std presp_std psoci_std{
    reg `var' ASQprimero if ChildID==1 & asq_present_b==1
	outreg2 using "Tables/Table A15. Regression Analysis of ASQ and Caregiver Questionnaire Implementation Order.xls", append dec(2)
    }

*----Order Effects & Treatment----**
reg ASQprimero trt if ChildID==1
	outreg2 using "Tables/Table A15. Regression Analysis of ASQ and Caregiver Questionnaire Implementation Order.xls", append dec(2)

*--------------------------------------------*
*                                            *
*    Participants in all waves      * 
*                                            *
*Note:This part is an alternative analysis for children and parents that participated 
//in all three waves of the program. The results are shown in the annex of the paper*

*----Generating dummy for participants in all waves----*
gen persistente_asq = 1 if asq_present_b==1 & asq_present_2==1 & asq_present_3==1 & ChildID==1  //
//kids who participated in all waves
gen persistente_cuid = 1 if cuid_present_b==1 & cuid_present_2==1 & cuid_present_3==1 & CuidID==1  //
//parents who participated in all waves

*---------------------------------*
*-----Child Development Impact----*
*---------------------------------*

*----standardizing ASQ scores for analysis for all three waves----*
foreach var of varlist pcom pmotg pmotf presp psoci{
sum `var' if persistente_asq==1 & ChildID==1  //sum mean and standard error
gen `var'_std3 =(`var'-r(mean))/r(sd)  //standardizing the scores 
sum `var'_std3 if persistente_asq==1 & ChildID==1  //testing the results
 
}

***** Generating index *******
gen asq_total3 = pcom_std3 + pmotg_std3 + pmotf_std3 + presp_std3 + psoci_std3
sum asq_total3 if persistente_asq==1 & ChildID==1  //sum mean and standard error
gen asq_total3_std3 =(asq_total3-r(mean))/r(sd)  //standardizing the scores 
sum asq_total3_std3 if persistente_asq==1 & ChildID==1  //testing the results 

***** Table A16. Impact on Child Development for children who participated in all three waves *****
foreach var in asq_total3_std3 pcom_std3 pmotg_std3 pmotf_std3 presp_std3 psoci_std3 {
	d `var'
	xtreg `var' trt_2 trt_3 wave2 wave3 if persistente_asq==1, fe i(community) vce(cluster community)
    outreg2 using  "Tables/Table A16.Impact on Child Development.xls", append label dec(2)
	}
	
*------------------------------------*
*----Observed Parenting Practices----*
*------------------------------------*
*----0-35 months----*
*---- Standardizing dummy variables for observed parenting practices----*
foreach var of varlist dummy_P64_CU-dummy_P72_CU {
sum `var' if persistente_asq==1 & ChildID==1  //sum mean and standard error
gen `var'_std3 = (`var'-r(mean))/r(sd)  //standardizing the scores 
sum `var'_std3 if persistente_asq==1 & ChildID==1  //testing the results 
}

* PCA
pca dummy_P64_CU_std3 - dummy_P72_CU_std3 if persistente_asq==1 & CuidID==1 & cuid_present_b==1
predict opi_pca3, score
sum opi_pca3 if persistente_asq==1 & ChildID==1  //sum mean and standard error
gen opi_pca3_std3 =(opi_pca3-r(mean))/r(sd)  //standardizing the scores 
sum opi_pca3_std3 if persistente_asq==1 & ChildID==1  //testing the results 

***** Table A17. Impact on Observed Parenting Practices for caregivers who participated in all three waves  - 9 practices + an index - age (0-3) *****

xtreg opi_pca3_std trt_2 trt_3 wave2 wave3 if persistente_cuid==1, fe i(community) vce(cluster ID_LOC)	
outreg2 using  "Tables/Table A17. Observed Parenting 0-35 (9 practices) for all three waves.xls", replace label dec(2)

foreach var of varlist dummy_P64_CU_std3 - dummy_P72_CU_std3 {
	d `var' 
	xtreg `var' trt_2 trt_3 wave2 wave3 if persistente_cuid==1, fe i(community) vce(cluster ID_LOC)	
	//gen sample_`var'=e(sample)
	//count if CuidID==1 & sample_`var'==1 & wave==1  //counting baseline sample size 
	outreg2 using  "Tables/Table A17. Observed Parenting 0-35 (9 practices) for all three waves.xls", append label dec(2)
	}
	
*----36-72 months----*
foreach var of varlist dummy_P73_CU-dummy_P84_CU {
	sum `var' if persistente_asq==1 & ChildID==1  //sum mean and standard error
	gen `var'_std3 = (`var'-r(mean))/r(sd)  //standardizing the scores 
	sum `var'_std3 if persistente_asq==1 & ChildID==1  //testing the results 
}
* PCA
pca dummy_P73_CU_std3 - dummy_P84_CU_std3 if persistente_asq==1 & CuidID==1 & cuid_present_b==1
predict opi2_pca3, score
sum opi2_pca3 if persistente_asq==1 & ChildID==1  //sum mean and standard error
gen opi2_pca3_std3 = (opi2_pca3-r(mean))/r(sd)  //standardizing the scores 
sum opi2_pca3_std3 if persistente_asq==1 & ChildID==1  //testing the results 
	
****** Table A18. Impact on Observed Parenting Practices for caregivers who participated in all three waves  - 12 practices + an index - age (36-72) ******
xtreg opi2_pca3_std trt_2 trt_3 wave2 wave3 if persistente_cuid==1, fe i(community) vce(cluster ID_LOC)	
outreg2 using  "Tables/Table A18. Observed Parenting 36-72 (9 practices) for all three waves.xls", replace label dec(2)

foreach var of varlist dummy_P73_CU_std3 - dummy_P84_CU_std3 {
	d `var' 
	xtreg `var' trt_2 trt_3 wave2 wave3 if persistente_cuid==1, fe i(community) vce(cluster ID_LOC)	
	//gen sample_`var'=e(sample)
	//count if CuidID==1 & sample_`var'==1 & wave==1  //counting baseline sample size 
	outreg2 using  "Tables/Table A18. Observed Parenting 36-72 (9 practices) for all three waves.xls", append label dec(2)
	}

* close log file and convert to PDF
	
	translate "Mexico ECD_logfile.smcl" "Mexico ECD_logfile.pdf", translator(smcl2pdf) replace
			
*-------------------------------------------------------------------------------
*                                   END                                        *
*-------------------------------------------------------------------------------
